$treeview $search $mathjax
|
Palabos
Version 1.1
$projectbrief
|
$projectbrief
|
$searchbox |
00001 /* This file is part of the Palabos library. 00002 * 00003 * Copyright (C) 2011 FlowKit Sarl 00004 * Avenue de Chailly 23 00005 * 1012 Lausanne, Switzerland 00006 * E-mail contact: contact@flowkit.com 00007 * 00008 * The most recent release of Palabos can be downloaded at 00009 * <http://www.palabos.org/> 00010 * 00011 * The library Palabos is free software: you can redistribute it and/or 00012 * modify it under the terms of the GNU Affero General Public License as 00013 * published by the Free Software Foundation, either version 3 of the 00014 * License, or (at your option) any later version. 00015 * 00016 * The library is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Affero General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Affero General Public License 00022 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00023 */ 00024 00025 /* Main author: Daniel Lagrava 00026 **/ 00027 00031 #ifndef SVG_WRITER_2D_H 00032 #define SVG_WRITER_2D_H 00033 00034 #include "multiGrid/multiGridManagement2D.h" 00035 #include "core/util.h" 00036 #include <string> 00037 00038 namespace plb { 00039 00040 int colors[128][3] = { 00041 { 255, 69, 0 }, { 30, 144, 255 }, { 0, 0, 255 }, { 255, 255, 0 }, { 0, 255, 255 }, { 00042 255, 0, 255 }, { 192, 192, 192 }, { 0, 0, 0}, 00043 { 200, 0, 0 }, { 0, 200, 0 }, { 0, 0, 200 }, { 200, 200, 0 }, { 0, 200, 200 }, { 200, 00044 0, 200 }, { 100, 100, 100 }, { 200, 200, 200}, 00045 { 100, 0, 0 }, { 0, 100, 0 }, { 0, 0, 100 }, { 100, 100, 0 }, { 0, 100, 100 }, { 100, 00046 0, 100 }, { 50, 50, 50 }, { 100, 100, 100}, 00047 { 50, 0, 0 }, { 0, 50, 0 }, { 0, 0, 50 }, { 50, 50, 0 }, { 0, 50, 50 }, { 50, 00048 0, 50 }, { 25, 25, 25 }, { 50, 50, 50}, 00049 { 255, 0, 0 }, { 0, 255, 0 }, { 0, 0, 255 }, { 255, 255, 0 }, { 0, 255, 255 }, { 255, 00050 0, 255 }, { 192, 192, 192 }, { 0, 0, 0}, 00051 { 200, 0, 0 }, { 0, 200, 0 }, { 0, 0, 200 }, { 200, 200, 0 }, { 0, 200, 200 }, { 200, 00052 0, 200 }, { 100, 100, 100 }, { 200, 200, 200}, 00053 { 100, 0, 0 }, { 0, 100, 0 }, { 0, 0, 100 }, { 100, 100, 0 }, { 0, 100, 100 }, { 100, 00054 0, 100 }, { 50, 50, 50 }, { 100, 100, 100}, 00055 { 50, 0, 0 }, { 0, 50, 0 }, { 0, 0, 50 }, { 50, 50, 0 }, { 0, 50, 50 }, { 50, 00056 0, 50 }, { 25, 25, 25 }, { 50, 50, 50}, 00057 { 255, 0, 0 }, { 0, 255, 0 }, { 0, 0, 255 }, { 255, 255, 0 }, { 0, 255, 255 }, { 255, 00058 0, 255 }, { 192, 192, 192 }, { 0, 0, 0}, 00059 { 200, 0, 0 }, { 0, 200, 0 }, { 0, 0, 200 }, { 200, 200, 0 }, { 0, 200, 200 }, { 200, 00060 0, 200 }, { 100, 100, 100 }, { 200, 200, 200}, 00061 { 100, 0, 0 }, { 0, 100, 0 }, { 0, 0, 100 }, { 100, 100, 0 }, { 0, 100, 100 }, { 100, 00062 0, 100 }, { 50, 50, 50 }, { 100, 100, 100}, 00063 { 50, 0, 0 }, { 0, 50, 0 }, { 0, 0, 50 }, { 50, 50, 0 }, { 0, 50, 50 }, { 50, 00064 0, 50 }, { 25, 25, 25 }, { 50, 50, 50}, 00065 { 255, 0, 0 }, { 0, 255, 0 }, { 0, 0, 255 }, { 255, 255, 0 }, { 0, 255, 255 }, { 255, 00066 0, 255 }, { 192, 192, 192 }, { 0, 0, 0}, 00067 { 200, 0, 0 }, { 0, 200, 0 }, { 0, 0, 200 }, { 200, 200, 0 }, { 0, 200, 200 }, { 200, 00068 0, 200 }, { 100, 100, 100 }, { 200, 200, 200}, 00069 { 100, 0, 0 }, { 0, 100, 0 }, { 0, 0, 100 }, { 100, 100, 0 }, { 0, 100, 100 }, { 100, 00070 0, 100 }, { 50, 50, 50 }, { 100, 100, 100}, 00071 { 50, 0, 0 }, { 0, 50, 0 }, { 0, 0, 50 }, { 50, 50, 0 }, { 0, 50, 50 }, { 50, 00072 0, 50 }, { 25, 25, 25 }, { 50, 50, 50} }; 00073 00074 00075 00076 00077 class SVGWriter2D { 00078 public: 00079 SVGWriter2D(MultiGridManagement2D management_): management(management_) 00080 {} 00081 00082 00083 void writePatterns(){ 00084 plint numLevels = management.getNumLevels(); 00085 out << "<defs>\n"; 00086 for (plint iLevel=0; iLevel<numLevels; ++iLevel){ 00087 double size = 20.0*util::twoToThePower(-iLevel); 00088 out << "<pattern id=\"Pat"<< size << "\" width=\""<< size << 00089 "\" height=\"" << size << "\" patternUnits=\"userSpaceOnUse\" >\n" << 00090 "\t<rect width=\"" << size << "\" height=\"" << size << 00091 "\" fill=\"none\" stroke=\"#000000\" stroke-width=\"2.0\" />\n</pattern>"; 00092 out << std::endl; 00093 } 00094 out << "</defs>\n"; 00095 } 00096 00097 void writeDomainsWithDynamicsInfo(std::string fileName, int dynamicsNumber, 00098 std::vector<MultiScalarField2D<int> > dynamicsInfo, 00099 std::vector<std::map<int, std::string> >& idToName, 00100 std::map<std::string,int>& nameToColor) 00101 { 00102 //std::vector<std::string> colors = createColors(dynamicsNumber); 00103 out.open(fileName.c_str()); 00104 Box2D finestBoundingBox = management.getBoundingBox(management.getNumLevels()-1); 00105 Dot2D size(finestBoundingBox.getNx(),finestBoundingBox.getNy()); 00106 writeHeader(); 00107 writePatterns(); 00108 00109 for (plint iLevel=0; iLevel<management.getNumLevels(); ++iLevel){ 00110 // write each block of the current level 00111 std::vector<Box2D> bulks = management.getBulks(iLevel); 00112 double size = util::twoToThePower(-iLevel); 00113 for (pluint iBlock=0; iBlock<bulks.size(); ++iBlock){ 00114 Box2D currentBlock = bulks[iBlock]; 00115 writeBG(currentBlock,size*20.0); 00116 for (plint iX=currentBlock.x0; iX<=currentBlock.x1; ++iX){ 00117 for (plint iY=currentBlock.y0; iY<=currentBlock.y1; ++iY){ 00118 //std::string color = colors[dynamicsInfo[iLevel].get(iX,iY)]; 00119 int id = nameToColor[idToName[iLevel][dynamicsInfo[iLevel].get(iX,iY)]]; 00120 if ( id != -1 ) { 00121 Array<double,2> location((double)iX*size*20.0,(double)iY*size*20.0); 00122 if (id >= 128) id=127; 00123 //writeRectangle(location, size, id); 00124 // writeCircle(location, size*10.0, id); 00125 //writeCircle(location, 7.0*size, id); 00126 00127 } 00128 } 00129 } 00130 } 00131 } 00132 writeEnd(); 00133 00134 } 00135 00136 void writeBG(Box2D block, double size){ 00137 double height = block.y1-block.y0 == 0? -size : (double)(block.y1-block.y0)*size; 00138 double width = block.x1-block.x0 == 0? -size :(double)(block.x1-block.x0)*size; 00139 double x0 = (double)block.x0*size; 00140 double y0 = (double)block.y0*size; 00141 out << "<rect x=\"" << x0 << "\" y=\""<< y0 << "\" width=\"" << width << "\" height=\"" << height 00142 <<"\" " << "style=\"stroke:black;fill:url(#Pat" << size << ")\"/>\n"; 00143 } 00144 00145 00146 private: 00147 // void writeHeader(Dot2D size){ 00148 // out << "<?xml version=\"1.0\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"" 00149 // << size.x << "cm\"" << "height=\""<< size.y << "cm\">\n"; 00150 // out << "\t<g style=\"fill-opacity:0.7; stroke:black; stroke-width:0.1cm;\">" << std::endl; 00151 // } 00152 00153 void writeHeader(){ 00154 out << "<?xml version=\"1.0\" standalone=\"no\"?>\n"; 00155 out << "<!DOCTYPE svg PUBLIC" 00156 << " \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"; 00157 out << "\t<svg width=\"100%\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"; 00158 out << std::endl; 00159 } 00160 00161 void writeCircle(Array<double,2> location, double radius, int color){ 00162 PLB_ASSERT( color>=0 && color <128 ); 00163 out << "<circle cx=\"" << location[0] << "\" cy=\"" << location[1] 00164 << "\" r=\"" << radius << "\" style=\"stroke:none; " << "fill-opacity:0.5; " 00165 <<"fill:" << "rgb(" << colors[color][0] << "," 00166 << colors[color][1] << "," << colors[color][2] << ")" << "\"/>" << std::endl; 00167 00168 } 00169 00170 void writeEnd(){ 00171 out << "</svg>" << std::endl; 00172 } 00173 00174 MultiGridManagement2D management; 00175 plb_ofstream out; 00176 }; 00177 00178 } // namespace plb 00179 00180 #endif // SVG_WRITER_2D_H 00181
1.6.3
1.6.3