32#include "DGtal/base/Common.h"
34#include "DGtal/io/viewers/PolyscopeViewer.h"
35#include "DGtal/io/readers/MeshReader.h"
36#include "DGtal/helpers/StdDefs.h"
37#include "DGtal/io/readers/PointListReader.h"
106 ImGuiIO& io = ImGui::GetIO();
110 if (ImGui::IsKeyPressed(ImGuiKey_W)) {
112 polyscope::options::buildGui = show_ui;
119int main(
int argc,
char **argv)
125 unsigned int meshColorR{240};
126 unsigned int meshColorG{240};
127 unsigned int meshColorB{240};
128 unsigned int meshColorA{255};
130 unsigned int meshColorRLine{0};
131 unsigned int meshColorGLine{0};
132 unsigned int meshColorBLine{0};
133 unsigned int meshColorALine{255};
135 unsigned int sdpColorR{240};
136 unsigned int sdpColorG{240};
137 unsigned int sdpColorB{240};
138 unsigned int sdpColorA{255};
140 float lineWidth{1.5};
142 std::vector<unsigned int> customColorMesh;
143 std::vector<unsigned int> customColorSDP;
144 std::vector<unsigned int> customLineColor;
145 std::vector<unsigned int> customBGColor;
146 std::vector<unsigned int> customAlphaMesh;
147 std::vector<unsigned int> vectFieldIndices = {0, 1, 2, 3, 4, 5};
148 std::string displayVectorField;
150 std::string snapshotFile;
151 std::string filenameSDP;
152 double ballRadius{0.5};
153 bool invertNormal{
false};
154 bool drawVertex{
false};
158 std::vector<std::string> inputFileNames;
159 std::string outputFileName{
"result.raw"};
160 app.description(
"Display OFF mesh file by using PolyscopeViewers");
161 app.add_option(
"-i,--input,1", inputFileNames,
"inputFileNames.off files (.off), or OFS file (.ofs)")
162 ->check(CLI::ExistingFile)
164 app.add_option(
"-x,--scaleX", sx,
"set the scale value in the X direction (default 1.0)");
165 app.add_option(
"-y,--scaleY", sy,
"set the scale value in the y direction (default 1.0)");
166 app.add_option(
"-z,--scaleZ", sz,
"set the scale value in the z direction (default 1.0)");
167 app.add_option(
"--minLineWidth", lineWidth,
"set the min line width of the mesh faces (default 1.5)");
168 app.add_option(
"--customColorMesh", customColorMesh,
"set the R, G, B, A components of the colors of the mesh faces and eventually the color R, G, B, A of the mesh edge lines (set by default to black).");
169 app.add_option(
"--customAlphaMesh", customAlphaMesh,
"set the alpha(A) components of the colors of the mesh faces (can be applied for each mesh).");
170 app.add_option(
"--customColorSDP", customColorSDP,
"set the R, G, B, A components of the colors of the sdp view")
172 app.add_option(
"--displayVectorField,-f", displayVectorField,
"display a vector field from a simple sdp file (two points per line)");
173 app.add_option(
"--vectorFieldIndex", vectFieldIndices,
"specify special indices for the two point coordinates (instead usinf the default indices: 0 1, 2, 3, 4, 5)")
175 app.add_option(
"--customLineColor", customLineColor,
"set the R, G, B components of the colors of the lines displayed from the --displayVectorField option (red by default).")
177 app.add_option(
"--SDPradius", ballRadius,
"change the ball radius to display a set of discrete points (used with displaySDP option)");
178 app.add_option(
"--displaySDP,-s", filenameSDP,
"add the display of a set of discrete points as ball of radius 0.5.");
179 app.add_flag(
"--invertNormal,-n", invertNormal,
"invert face normal vectors.");
180 app.add_flag(
"--drawVertex,-v", drawVertex,
"draw the vertex of the mesh");
182 app.get_formatter()->column_width(40);
183 CLI11_PARSE(app, argc, argv);
186 DGtal::Color vFieldLineColor = DGtal::Color::Red;
187 if (customLineColor.size() == 4)
189 vFieldLineColor.setRGBi(customLineColor[0], customLineColor[1], customLineColor[2], 255);
192 if (customColorMesh.size() != 0)
194 if (customColorMesh.size() < 4)
196 trace.error() <<
"colors specification should contain R,G,B and Alpha values" << std::endl;
200 if (customColorSDP.size() == 4)
202 sdpColorR = customColorSDP[0];
203 sdpColorG = customColorSDP[1];
204 sdpColorB = customColorSDP[2];
205 sdpColorA = customColorSDP[3];
210 s <<
"meshViewer - DGtalTools: ";
211 string name = inputFileNames[0].substr(inputFileNames[0].find_last_of(
"/")+1,inputFileNames[0].size()) ;
212 s <<
" " << name <<
" (W key to display settings)";
213 polyscope::options::programName = s.str();
214 polyscope::options::buildGui=
false;
215 polyscope::options::groundPlaneMode = polyscope::GroundPlaneMode::None;
216 polyscope::view::setNavigateStyle(polyscope::NavigateStyle::Free);
219 PolyscopeViewer viewer;
221 viewer.allowReuseList =
true;
222 trace.info() <<
"Importing mesh... ";
224 std::vector<Mesh<DGtal::Z3i::RealPoint>> vectMesh;
225 for (
unsigned int i = 0; i < inputFileNames.size(); i++)
227 Mesh<DGtal::Z3i::RealPoint> aMesh(customColorMesh.size() != 4 && customColorMesh.size() != 8);
228 aMesh << inputFileNames[i];
230 if (aMesh.isStoringFaceColors() && customColorMesh.size() >= 4)
232 if (i * 8 < customColorMesh.size())
234 meshColorR = customColorMesh[i * 8];
236 if (i * 8 + 1 < customColorMesh.size())
238 meshColorG = customColorMesh[i * 8 + 1];
240 if (i * 8 + 2 < customColorMesh.size())
242 meshColorB = customColorMesh[i * 8 + 2];
244 if (i * 8 + 3 < customColorMesh.size())
246 meshColorA = customColorMesh[i * 8 + 3];
248 for (
unsigned int j = 0; j < aMesh.nbFaces(); j++)
250 aMesh.setFaceColor(j, Color(meshColorR, meshColorG, meshColorB, meshColorA));
253 else if (customAlphaMesh.size() > 0)
255 for (
unsigned int j = 0; j < aMesh.nbFaces(); j++)
257 auto c = aMesh.getFaceColor(j);
258 aMesh.setFaceColor(j, Color(c.red(), c.green(), c.blue(), customAlphaMesh.at(i < customAlphaMesh.size() ? i : 0)));
262 vectMesh.push_back(aMesh);
265 bool import = vectMesh.size() == inputFileNames.size();
268 trace.info() <<
"File import failed. " << std::endl;
272 trace.info() <<
"[done]. " << std::endl;
273 if (filenameSDP !=
"")
275 if (customAlphaMesh.size() > 0)
277 trace.info() <<
"New meshViewer" << std::endl;
278 auto vOrigins = PointListReader<PointVector<1, DGtal::int32_t>>::getPolygonsFromFile(filenameSDP);
279 viewer << Color(sdpColorR, sdpColorG, sdpColorB, sdpColorA);
280 for (
auto l : vOrigins)
282 DGtal::Z3i::Point pt(l[0][0], l[1][0], l[2][0]);
283 DGtal::Color cl(l[3][0], l[4][0], l[5][0], sdpColorA);
284 viewer.drawColor(cl);
290 vector<Z3i::RealPoint> vectPoints;
291 vectPoints = PointListReader<Z3i::RealPoint>::getPointsFromFile(filenameSDP);
292 viewer << Color(sdpColorR, sdpColorG, sdpColorB, sdpColorA);
293 for (
unsigned int i = 0; i < vectPoints.size(); i++)
295 viewer.drawBall(vectPoints.at(i));
301 for (
unsigned int i = 0; i < vectMesh.size(); i++)
303 vectMesh[i].invertVertexFaceOrder();
307 for (
unsigned int i = 0; i < vectMesh.size(); i++)
309 if (i * 8 < customColorMesh.size())
311 meshColorR = customColorMesh[i * 8];
313 if (i * 8 + 1 < customColorMesh.size())
315 meshColorG = customColorMesh[i * 8 + 1];
317 if (i * 8 + 2 < customColorMesh.size())
319 meshColorB = customColorMesh[i * 8 + 2];
321 if (i * 8 + 3 < customColorMesh.size())
323 meshColorA = customColorMesh[i * 8 + 3];
325 if (i * 8 + 4 < customColorMesh.size())
327 meshColorALine = customColorMesh[i * 8 + 4];
329 if (i * 8 + 5 < customColorMesh.size())
331 meshColorBLine = customColorMesh[i * 8 + 5];
333 if (i * 8 + 6 < customColorMesh.size())
335 meshColorRLine = customColorMesh[i * 8 + 6];
337 if (i * 8 + 7 < customColorMesh.size())
339 meshColorALine = customColorMesh[i * 8 + 7];
342 viewer << Color(meshColorR, meshColorG, meshColorB, meshColorA);
343 viewer << vectMesh[i];
348 for (
unsigned int i = 0; i < vectMesh.size(); i++)
350 for (Mesh<DGtal::Z3i::RealPoint>::VertexStorage::const_iterator it = vectMesh[i].vertexBegin();
351 it != vectMesh[i].vertexEnd(); ++it)
353 DGtal::Z3i::Point pt;
362 if (displayVectorField !=
"")
364 std::vector<unsigned int> vectFieldIndices1 = {vectFieldIndices[0], vectFieldIndices[1], vectFieldIndices[2]};
365 std::vector<unsigned int> vectFieldIndices2 = {vectFieldIndices[3], vectFieldIndices[4], vectFieldIndices[5]};
366 std::vector<DGtal::Z3i::RealPoint> vectPt1 = PointListReader<DGtal::Z3i::RealPoint>::getPointsFromFile(displayVectorField, vectFieldIndices1);
367 std::vector<DGtal::Z3i::RealPoint> vectPt2 = PointListReader<DGtal::Z3i::RealPoint>::getPointsFromFile(displayVectorField, vectFieldIndices2);
368 for (
unsigned int i = 0; i < vectPt1.size(); i++)
370 viewer.drawColor(vFieldLineColor);
371 viewer.drawLine(vectPt1[i], vectPt2[i]);
374 unsigned int nbVertex = 0;
375 unsigned int nbFaces = 0;
376 for (
auto const &m : vectMesh)
378 nbVertex += m.nbVertex();
379 nbFaces += m.nbFaces();
382 ss <<
"# faces: " << std::fixed << nbFaces <<
" #vertex: " << nbVertex;
383 trace.info() <<
"[display ready]" << std::endl;
384 polyscope::state::userCallback = myCallback;