VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
WbWriterX3D.cpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
36
37using namespace std;
38
39/*===============================================================================*/
40std::string WbWriterX3D::writeTriangles(const string &filename, vector<UbTupleFloat3> &nodes,
41 vector<UbTupleInt3> &triangles)
42{
43 string X3DFilename = filename + getFileExtension();
44 UBLOG(logDEBUG1, "WbWriterX3D::writeTriangles to " << X3DFilename << " - start");
45
46 std::ofstream out(X3DFilename.c_str());
47 if (!out) {
48 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
50 if (path.size() > 0) {
52 out.open(X3DFilename.c_str());
53 }
54 if (!out)
55 throw UbException(UB_EXARGS, "couldn't open file " + X3DFilename);
56 }
57
58 // General part
59
60 // Root Element
61 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
62 out << "<!DOCTYPE X3D PUBLIC \"ISO//Web3D//DTD X3D 3.1//EN\" \"http://www.web3d.org/specifications/x3d-3.1.dtd\">"
63 << endl;
64 out << "<X3D profile='Interchange' version='3.1' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' "
65 "xsd:noNamespaceSchemaLocation=' http://www.web3d.org/specifications/x3d-3.1.xsd '>"
66 << endl
67 << endl;
68
69 // Head
70 out << "<head>" << endl;
71 out << "<meta content='Simple X3D Writer for blender'/>" << endl;
72 out << "</head>" << endl << endl;
73
74 // Scene, Shape beginn
75 out << "<Scene>" << endl;
76 out << "<Shape>" << endl;
77
78 // IndexedFaceSet => Polylinien der Dreiecke
79 out << "<IndexedFaceSet coordIndex=\"" << endl;
80
81 // TRIANGLES Ponits SECTION
82 int nofTriangles = (int)triangles.size();
83 // out<<" triangles "<<nofTriangles<<endl;
84 for (int c = 0; c < nofTriangles; c++)
85 out << " " << val<1>(triangles[c]) << " " << val<2>(triangles[c]) << " " << val<3>(triangles[c]) << " -1"
86 << endl;
87 out << "\">" << endl;
88
89 // Coordinates
90 out << "<Coordinate point=\"" << endl;
91
92 // Coordinates SECTION
93 int nofNodes = (int)nodes.size();
94 // out<<" points "<<nofNodes<<endl;
95 for (int n = 0; n < nofNodes; n++)
96 out << " " << val<1>(nodes[n]) << ", " << val<2>(nodes[n]) << ", " << val<3>(nodes[n]) << ", " << endl;
97 out << "\"/>" << endl;
98
99 // Footer
100 out << "</IndexedFaceSet>" << endl;
101 out << "</Shape>" << endl;
102 out << "</Scene>" << endl;
103 out << "</X3D>" << endl;
104
106 // out<<"image {" <<endl;
107 // out<<" resolution 640 480"<<endl;
108 // out<<" aa 0 1" <<endl;
109 // out<<" filter mitchell" <<endl;
110 // out<<"}" <<endl<<endl;
111
113 // out<<"camera {" <<endl;
114 // out<<" type pinhole" <<endl;
115 // out<<" eye -0.25 -0.3 0.13"<<endl;
116 // out<<" target -0.1 0.1 0.13" <<endl;
117 // out<<" up 0 0 1" <<endl;
118 // out<<" fov 60" <<endl;
119 // out<<" aspect 1.333333" <<endl;
120 // out<<"}" <<endl<<endl;
121
123 // out<<"light {" <<endl;
124 // out<<" type ibl" <<endl;
125 // out<<" image sky_small.hdr" <<endl;
126 // out<<" center 0 -1 0" <<endl;
127 // out<<" up 0 0 1" <<endl;
128 // out<<" lock true" <<endl;
129 // out<<" samples 200" <<endl;
130 // out<<"}" <<endl<<endl;
131
133 // out<<"shader {" <<endl;
134 // out<<" name default-shader" <<endl;
135 // out<<" type diffuse" <<endl;
136 // out<<" diff 0.25 0.25 0.25" <<endl;
137 // out<<"}" <<endl<<endl;
138
139 // out<<"shader {" <<endl;
140 // out<<" name Glass" <<endl;
141 // out<<" type glass" <<endl;
142 // out<<" eta 1.333" <<endl;
143 // out<<" color 0.1 0.3 0.8" <<endl;
144 // out<<"}" <<endl<<endl;
145 //
146 // out<<"shader {" <<endl;
147 // out<<" name Mirror" <<endl;
148 // out<<" type mirror" <<endl;
149 // out<<" refl 0.7 0.7 0.7" <<endl;
150 // out<<"}" <<endl<<endl;
151
154 // out<<"object {" <<endl;
155 // out<<" shader default-shader" <<endl;
156 // out<<" type plane" <<endl;
157 // out<<" p 0 0 0" <<endl;
158 // out<<" n 0 0 1" <<endl;
159 // out<<"}" <<endl<<endl;
160
162 // out<<"object {" <<endl;
163 // out<<" shader Glass" <<endl;
164 // out<<" transform {" <<endl;
165 // out<<" rotatey 270.0" <<endl;
166 // out<<" }" <<endl;
167 // out<<" type generic-mesh" <<endl;
168 // out<<" name polySurfac" <<endl<<endl;
169
171 // int nofNodes = (int)nodes.size();
172 // out<<" points "<<nofNodes<<endl;
173 // for(int n=0; n<nofNodes; n++)
174 // out<<" "<< val<1>(nodes[n]) <<" "<< val<2>(nodes[n]) <<" "<< val<3>(nodes[n]) <<endl;
175
177 // int nofTriangles= (int)triangles.size();
178 // out<<" triangles "<<nofTriangles<<endl;
179 // for(int c=0; c<nofTriangles; c++)
180 // out<<" "<<val<1>(triangles[c]) <<" "<< val<2>(triangles[c])<<" "<< val<3>(triangles[c])<<endl;
181
183 // out<<" normals none" << endl;
184 // out<<" uvs none" << endl;
185 // out<<"}" << endl;
186
187 out.close();
188 UBLOG(logDEBUG1, "WbWriterX3D::writeTriangles to " << X3DFilename << " - end");
189
190 return X3DFilename;
191}
192/*===============================================================================*/
193
std::string getFileExtension() override
Definition WbWriterX3D.h:67
std::shared_ptr< T > SPtr
#define UBLOG(level, logtext)
Definition UbLogger.h:327
#define UB_EXARGS
Definition UbException.h:73
@ logDEBUG1
Definition UbLogger.h:54
std::string writeTriangles(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt3 > &triangles) override
bool makeDirectory(const std::string &dir)
Definition UbSystem.h:280
std::string getPathFromString(const std::string &fileStringWithPath)
Definition UbSystem.h:345