/usr/include/palabos/multiGrid/svgWriter.h is in libplb-dev 1.5~r1+repack1-2build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | /* This file is part of the Palabos library.
*
* Copyright (C) 2011-2015 FlowKit Sarl
* Route d'Oron 2
* 1010 Lausanne, Switzerland
* E-mail contact: contact@flowkit.com
*
* The most recent release of Palabos can be downloaded at
* <http://www.palabos.org/>
*
* The library Palabos is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* The library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* Main author: Daniel Lagrava
**/
/** \file
* SVG writer for refined
*/
#ifndef SVG_WRITER_2D_H
#define SVG_WRITER_2D_H
#include "multiGrid/multiGridManagement2D.h"
#include "core/util.h"
#include <string>
namespace plb {
class SVGWriter2D {
public:
SVGWriter2D(MultiGridManagement2D management_): management(management_)
{}
void writePatterns(){
plint numLevels = management.getNumLevels();
out << "<defs>\n";
for (plint iLevel=0; iLevel<numLevels; ++iLevel){
double size = 20.0*util::twoToThePower(-iLevel);
out << "<pattern id=\"Pat"<< size << "\" width=\""<< size <<
"\" height=\"" << size << "\" patternUnits=\"userSpaceOnUse\" >\n" <<
"\t<rect width=\"" << size << "\" height=\"" << size <<
"\" fill=\"none\" stroke=\"#000000\" stroke-width=\"2.0\" />\n</pattern>";
out << std::endl;
}
out << "</defs>\n";
}
void writeDomainsWithDynamicsInfo(std::string fileName, int dynamicsNumber,
std::vector<MultiScalarField2D<int> > dynamicsInfo,
std::vector<std::map<int, std::string> >& idToName,
std::map<std::string,int>& nameToColor)
{
//std::vector<std::string> colors = createColors(dynamicsNumber);
out.open(fileName.c_str());
Box2D finestBoundingBox = management.getBoundingBox(management.getNumLevels()-1);
Dot2D size(finestBoundingBox.getNx(),finestBoundingBox.getNy());
writeHeader();
writePatterns();
for (plint iLevel=0; iLevel<management.getNumLevels(); ++iLevel){
// write each block of the current level
std::vector<Box2D> bulks = management.getBulks(iLevel);
double size = util::twoToThePower(-iLevel);
for (pluint iBlock=0; iBlock<bulks.size(); ++iBlock){
Box2D currentBlock = bulks[iBlock];
writeBG(currentBlock,size*20.0);
for (plint iX=currentBlock.x0; iX<=currentBlock.x1; ++iX){
for (plint iY=currentBlock.y0; iY<=currentBlock.y1; ++iY){
//std::string color = colors[dynamicsInfo[iLevel].get(iX,iY)];
int id = nameToColor[idToName[iLevel][dynamicsInfo[iLevel].get(iX,iY)]];
if ( id != -1 ) {
Array<double,2> location((double)iX*size*20.0,(double)iY*size*20.0);
if (id >= 128) id=127;
//writeRectangle(location, size, id);
// writeCircle(location, size*10.0, id);
//writeCircle(location, 7.0*size, id);
}
}
}
}
}
writeEnd();
}
void writeDomainsWithDynamicsInfo(std::string fileName, int dynamicsNumber,
std::vector<std::vector<Box2D> > blocks,
std::vector<MultiScalarField2D<int> > dynamicsInfo,
std::vector<std::map<int, std::string> >& idToName,
std::map<std::string,int>& nameToColor)
{
//std::vector<std::string> colors = createColors(dynamicsNumber);
out.open(fileName.c_str());
Box2D finestBoundingBox = management.getBoundingBox(management.getNumLevels()-1);
Dot2D size(finestBoundingBox.getNx(),finestBoundingBox.getNy());
writeHeader();
writePatterns();
for (plint iLevel=0; iLevel<management.getNumLevels(); ++iLevel){
// write each block of the current level
std::vector<Box2D> bulks = blocks[iLevel];
double size = util::twoToThePower(-iLevel);
for (pluint iBlock=0; iBlock<bulks.size(); ++iBlock){
Box2D currentBlock = bulks[iBlock];
writeBG(currentBlock,size*20.0);
for (plint iX=currentBlock.x0; iX<=currentBlock.x1; ++iX){
for (plint iY=currentBlock.y0; iY<=currentBlock.y1; ++iY){
//std::string color = colors[dynamicsInfo[iLevel].get(iX,iY)];
int id = nameToColor[idToName[iLevel][dynamicsInfo[iLevel].get(iX,iY)]];
if ( id != -1 ) {
Array<double,2> location((double)iX*size*20.0,(double)iY*size*20.0);
}
}
}
}
}
writeEnd();
}
void writeBG(Box2D block, double size){
double height = block.y1-block.y0 == 0? -size : (double)(block.y1-block.y0)*size;
double width = block.x1-block.x0 == 0? -size :(double)(block.x1-block.x0)*size;
double x0 = (double)block.x0*size;
double y0 = (double)block.y0*size;
out << "<rect x=\"" << x0 << "\" y=\""<< y0 << "\" width=\"" << width << "\" height=\"" << height
<<"\" " << "style=\"stroke:black;fill:url(#Pat" << size << ")\"/>\n";
}
private:
// void writeHeader(Dot2D size){
// out << "<?xml version=\"1.0\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\""
// << size.x << "cm\"" << "height=\""<< size.y << "cm\">\n";
// out << "\t<g style=\"fill-opacity:0.7; stroke:black; stroke-width:0.1cm;\">" << std::endl;
// }
void writeHeader(){
out << "<?xml version=\"1.0\" standalone=\"no\"?>\n";
out << "<!DOCTYPE svg PUBLIC"
<< " \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
out << "\t<svg width=\"100%\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">";
out << std::endl;
}
/*void writeCircle(Array<double,2> location, double radius, int color){
PLB_ASSERT( color>=0 && color <128 );
out << "<circle cx=\"" << location[0] << "\" cy=\"" << location[1]
<< "\" r=\"" << radius << "\" style=\"stroke:none; " << "fill-opacity:0.5; "
<<"fill:" << "rgb(" << colors[color][0] << ","
<< colors[color][1] << "," << colors[color][2] << ")" << "\"/>" << std::endl;
}*/
void writeEnd(){
out << "</svg>" << std::endl;
}
MultiGridManagement2D management;
plb_ofstream out;
};
} // namespace plb
#endif // SVG_WRITER_2D_H
|