Commit 26c9c6bf authored by COULAUD Olivier's avatar COULAUD Olivier

Add vtk, vtp and cosmos format for visualization

parent ae4a8d6d
......@@ -33,6 +33,7 @@
//! \param -filename name: generic name for files (without extension) and save data
//! with following format in name.xxx or name.bin in -bin (not yet implemented) is set
//! \param -visu save output in filename.txt
//! \param -visufmt format for the visu file (vtk, vtp, cvs or cosmo). vtp is the default
//!
//! <b> Geometry arguments:</b>
//! \param -unitSphere uniform distribution on unit sphere
......@@ -58,7 +59,7 @@
//
//
void genDistusage() {
void genDistusage() {
std::cout << "Driver to generate N points (non)uniformly distributed on a given geometry"
<< std::endl;
std::cout << "Options "<< std::endl
......@@ -82,8 +83,9 @@
<< " Output " << std::endl
<< " -filename name: generic name for files (without extension) and save data" <<std::endl
<< " with following format in name.xxx or name.bin in -bin is set" <<std::endl
<< " -visu save output in name.txt" <<std::endl;
}
<< " -visu save output in name.txt" <<std::endl
<< " -visufmt vtk, vtp, cosmo or cvs format " <<std::endl;
}
int main(int argc, char ** argv){
//
......@@ -165,8 +167,22 @@ int main(int argc, char ** argv){
std::cout << "Bad geometry option"<< std::endl;
exit(-1) ;
}
if(FParameters::existParameter(argc, argv, "-visu")){
std::ofstream file( genericFileName + ".txt", std::ofstream::out);
std::string visufile(""), fmt(FParameters::getStr(argc,argv,"-visufmt", "vtp"));
if( fmt == "vtp" ){
visufile = genericFileName + ".vtp" ;
}
else if( fmt == "vtk" ){
visufile = genericFileName + ".vtk" ;
}
else if( fmt == "cosmo" ){
visufile = genericFileName + ".cosmo" ;
}
else {
visufile = genericFileName + ".csv" ;
}
std::ofstream file( visufile, std::ofstream::out);
if(!file) {
std::cout << "Cannot open file."<< std::endl;
exit(-1) ;
......@@ -174,11 +190,22 @@ int main(int argc, char ** argv){
//
// Export data in cvs format
//
std::cout << "Writes in CVS format (visualization) in file "<< genericFileName + ".txt" <<std::endl ;
if( fmt == "vtp" ){
std::cout << "Writes in XML VTP format (visualization) in file "<< visufile <<std::endl ;
exportVTKxml( file, NbPoints, particles) ;
}
else if( fmt == "vtk" ){
std::cout << "Writes in VTK format (visualization) in file "<< visufile <<std::endl ;
exportVTK( file, NbPoints, particles) ;
}
else if( fmt == "cosmo" ){
std::cout << "Writes in COSMO format (visualization) in file "<< visufile <<std::endl ;
exportCOSMOS( file, NbPoints, particles) ;
}
else {
std::cout << "Writes in CVS format (visualization) in file "<<visufile<<std::endl ;
exportCVS( file, NbPoints, particles) ;
//
// Export data in vtk format
//
}
}
//
// Generate file for ScalFMM Loader
......@@ -202,5 +229,4 @@ int main(int argc, char ** argv){
//
return 1;
}
}
......@@ -199,14 +199,93 @@ void exportCVS(std::ofstream& file, const int N, const FReal * particles ){
file << particles[j] << " , " << particles[j+1] << " , " << particles[j+2] << " , " << particles[j+3] <<std::endl;
}
}
void exportVTK(std::ofstream& file, const int N, const FReal * particles ){
//
void exportCOSMOS(std::ofstream& file, const int N, const FReal * particles ){
int j = 0;
file << " x , y , z, q " <<std::endl;
for(int i = 0 ; i< N; ++i, j+=4){
file << particles[j] << " , " << particles[j+1] << " , " << particles[j+2] << " , " << particles[j+3] <<std::endl;
file << particles[j] << " " << particles[j+1] << " " << particles[j+2] << " 0.0 0.0 0.0 " << particles[j+3] <<" " << i << std::endl;
}
}
//
void exportVTK(std::ofstream& VTKfile, const int N, const FReal * particles ){
int j = 0;
//---------------------------
// print generic information
//---------------------------
VTKfile << "# vtk DataFile Version 3.0" << "\n";
VTKfile << "# Generated bt exportVTK" << "\n";
VTKfile << "ASCII" << "\n";
VTKfile << "DATASET POLYDATA" << "\n";
//
//---------------------------------
// print nodes ordered by their TAG
//---------------------------------
VTKfile << "POINTS " << N << " float" << "\n";
//
for(int i = 0 ; i< N; ++i, j+=4){
VTKfile << particles[j] << " " << particles[j+1] << " " << particles[j+2] <<std::endl;
}
// ------------------------------------------
VTKfile << "\n";
VTKfile << "VERTICES " << N << " " << 2*N << "\n";
for(int i = 0 ; i< N; ++i, j+=4){
VTKfile << " 1 " << " " <<i<<std::endl;
}
VTKfile << "POINT_DATA " << N << "\n";
VTKfile << "SCALARS PhysicalValue float 1" << "\n"
<< "LOOKUP_TABLE default" << "\n" ;
j = 0 ;
for(int i = 0 ; i< N; ++i, j+=4){
VTKfile << particles[j+3] << " " <<std::endl;
}
VTKfile << "\n";
};
void exportVTKxml(std::ofstream& VTKfile, const int N, const FReal * particles ){
int j = 0;
VTKfile << "<?xml version=\"1.0\"?>" <<std::endl
<< "<VTKFile type=\"PolyData\" version=\"0.1\" byte_order=\"LittleEndian\"> "<<std::endl
<< "<PolyData>"<<std::endl
<< "<Piece NumberOfPoints=\" " << N << " \" NumberOfVerts=\" "<<N <<" \" NumberOfLines=\" 0\" NumberOfStrips=\"0\" NumberOfPolys=\"0\">"<<std::endl
<< "<Points>"<<std::endl
<< "<DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\"> "<<std::endl ;
j = 0 ;
for(int i = 0 ; i< N; ++i, j+=4){
VTKfile << particles[j] << " " << particles[j+1] << " " << particles[j+2] << " " ;
}
VTKfile <<std::endl<< "</DataArray> "<<std::endl
<< "</Points> "<<std::endl
<< "<PointData Scalars=\"PhysicalValue\" > "<<std::endl
<< "<DataArray type=\"Float64\" Name=\"PhysicalValue\" format=\"ascii\">"<<std::endl ;
j = 0 ;
for(int i = 0 ; i< N; ++i, j+=4){
VTKfile << particles[j+3] << " " ;
}
VTKfile <<std::endl << "</DataArray>"<<std::endl
<< " </PointData>"<<std::endl
<< " <CellData>"<<" </CellData>"<<std::endl
<< " <Verts>"<<std::endl
<< " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">"<<std::endl ;
for(int i = 0 ; i< N; ++i){
VTKfile << i << " " ;
}
VTKfile<<std::endl << "</DataArray>" <<std::endl
<< "<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">"<<std::endl ;
for(int i = 1 ; i< N+1; ++i){
VTKfile << i << " " ;
}
VTKfile<<std::endl << "</DataArray>"<<std::endl
<< " </Verts>"<<std::endl
<< "<Lines></Lines>"<<std::endl
<< "<Strips></Strips>"<<std::endl
<< "<Polys></Polys>"<<std::endl
<< "</Piece>"<<std::endl
<< "</PolyData>"<<std::endl
<< "</VTKFile>"<<std::endl;
} ;
//
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment