void write_explicit_surface_vtk(const levelset<GridTraitsType, LevelSetTraitsType>& l, const std::string& filename, const DataType& Data, typename LevelSetTraitsType::value_type eps=0.) { //this function etracts the surface using the marching cubes algorithm and writes it to the specified file using vtk-file format //the parameter eps is forwarded to the surface extraction function const int D=GridTraitsType::dimensions; Surface<D> s; typename GetActivePointType<typename LevelSetTraitsType::size_type, DataType>::result ActivePointList; extract(l, s, eps, ActivePointList); std::ofstream f(filename.c_str()); f << "# vtk DataFile Version 2.0" << std::endl; f << D << "D Surface" << std::endl; f << "ASCII" << std::endl; f << "DATASET UNSTRUCTURED_GRID" << std::endl; f << "POINTS " << s.Nodes.size() << " float" << std::endl; //!print positions for (unsigned int i=0;i<s.Nodes.size();i++) { for (int j=0;j<D;j++) f << static_cast<float>(s.Nodes[i][j]) << " "; if (D==2) f << "0. "; f<< std::endl; } f << "CELLS " << s.Elements.size() << " " << ((D+1)*s.Elements.size()) << std::endl; for (unsigned int i=0;i<s.Elements.size();i++) { f << D << " "; for (int j=0;j<D;j++) f<< s.Elements[i][j] << " "; f << std::endl; } f << "CELL_TYPES " << s.Elements.size() << std::endl; for (unsigned int i=0;i<s.Elements.size();i++) { f<< ((D==3)?"5":"3") << std::endl; } //output data f << "POINT_DATA " << s.Nodes.size() << std::endl; for (int k=0;k<Data.number_of_series();++k) { if (Data.get_series_output(k)) { f << "SCALARS " << Data.get_series_label(k) << " " << Data.get_series_type(k) << " 1" << std::endl; f << "LOOKUP_TABLE default" << std::endl; for (unsigned int i=0;i<s.Nodes.size();i++) { f << Data.get_series_data(ActivePointList[i],k) << std::endl; } } } f.close(); }
void write_explicit_surface_opendx(const levelset<GridTraitsType, LevelSetTraitsType>& l, const std::string& filename, const DataType& Data, typename LevelSetTraitsType::value_type eps=0.) { //this function etracts the surface using the marching cubes algorithm and writes it to the specified file using OpenDX-file format //the parameter eps is forwarded to the surface extraction function const int D=GridTraitsType::dimensions; Surface<D> s; typename GetActivePointType<typename LevelSetTraitsType::size_type, DataType>::result ActivePointList; extract(l, s, eps, ActivePointList); std::ofstream f(filename.c_str()); //!print positions f<< "object \"positions\" class array type float rank 1 shape " << D << " items "<< s.Nodes.size() <<" data follows" << std::endl; for (unsigned int i=0;i<s.Nodes.size();i++) { for (int j=0;j<D;j++) f << static_cast<float>(s.Nodes[i][j]) << " "; f<< std::endl; } //! print connections f << "object \"connections\" class array type int rank 1 shape " << D << " items "<< s.Elements.size() <<" data follows" << std::endl; for (unsigned int i=0;i<s.Elements.size();i++) { for (int j=0;j<D;j++) f<< s.Elements[i][j] << " "; f << std::endl; } if (D==2) f << "attribute \"element type\" string \"lines\"" << std::endl; else if (D==3) f << "attribute \"element type\" string \"triangles\"" << std::endl; f << "attribute \"ref\" string \"positions\"" << std::endl; //output data for (int k=0;k<Data.number_of_series();++k) { if (Data.get_series_output(k)) { f << "object \"" << Data.get_series_label(k) << "_data\" class array type " << Data.get_series_type(k) << " rank 0 items " << s.Nodes.size() << " data follows" << std::endl; for (unsigned int i=0;i<s.Nodes.size();i++) { f << Data.get_series_data(ActivePointList[i],k) << std::endl; } f << "attribute \"dep\" string \"positions\"" << std::endl; } } //! print profile f << "object \"profile\" class field" << std::endl; f << " component \"positions\" value \"positions\"" << std::endl; f << " component \"connections\" value \"connections\"" << std::endl; for (int k=0;k<Data.number_of_series();++k) { if (Data.get_series_output(k)) { f << "object \""<< Data.get_series_label(k) << "\" class field" << std::endl; f << " component \"positions\" value \"positions\"" << std::endl; f << " component \"connections\" value \"connections\"" << std::endl; f << " component \"data\" value \"" << Data.get_series_label(k) << "_data\"" << std::endl; } } f << "end" << std::endl; f.close(); }