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"
105 ImGuiIO& io = ImGui::GetIO();
109 if (ImGui::IsKeyPressed(ImGuiKey_W)) {
111 polyscope::options::buildGui = show_ui;
118int main(
int argc,
char **argv)
124 unsigned int meshColorR{240};
125 unsigned int meshColorG{240};
126 unsigned int meshColorB{240};
127 unsigned int meshColorA{255};
129 unsigned int meshColorRLine{0};
130 unsigned int meshColorGLine{0};
131 unsigned int meshColorBLine{0};
132 unsigned int meshColorALine{255};
134 unsigned int sdpColorR{240};
135 unsigned int sdpColorG{240};
136 unsigned int sdpColorB{240};
137 unsigned int sdpColorA{255};
139 float lineWidth{1.5};
141 std::vector<unsigned int> customColorMesh;
142 std::vector<unsigned int> customColorSDP;
143 std::vector<unsigned int> customLineColor;
144 std::vector<unsigned int> customBGColor;
145 std::vector<unsigned int> customAlphaMesh;
146 std::vector<unsigned int> vectFieldIndices = {0, 1, 2, 3, 4, 5};
147 std::string displayVectorField;
149 std::string snapshotFile;
150 std::string filenameSDP;
151 double ballRadius{0.5};
152 bool invertNormal{
false};
153 bool drawVertex{
false};
157 std::vector<std::string> inputFileNames;
158 std::string outputFileName{
"result.raw"};
159 app.description(
"Display OFF mesh file by using PolyscopeViewers");
160 app.add_option(
"-i,--input,1", inputFileNames,
"inputFileNames.off files (.off), or OFS file (.ofs)")
161 ->check(CLI::ExistingFile)
163 app.add_option(
"-x,--scaleX", sx,
"set the scale value in the X direction (default 1.0)");
164 app.add_option(
"-y,--scaleY", sy,
"set the scale value in the y direction (default 1.0)");
165 app.add_option(
"-z,--scaleZ", sz,
"set the scale value in the z direction (default 1.0)");
166 app.add_option(
"--minLineWidth", lineWidth,
"set the min line width of the mesh faces (default 1.5)");
167 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).");
168 app.add_option(
"--customAlphaMesh", customAlphaMesh,
"set the alpha(A) components of the colors of the mesh faces (can be applied for each mesh).");
169 app.add_option(
"--customColorSDP", customColorSDP,
"set the R, G, B, A components of the colors of the sdp view")
171 app.add_option(
"--displayVectorField,-f", displayVectorField,
"display a vector field from a simple sdp file (two points per line)");
172 app.add_option(
"--vectorFieldIndex", vectFieldIndices,
"specify special indices for the two point coordinates (instead usinf the default indices: 0 1, 2, 3, 4, 5)")
174 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).")
176 app.add_option(
"--SDPradius", ballRadius,
"change the ball radius to display a set of discrete points (used with displaySDP option)");
177 app.add_option(
"--displaySDP,-s", filenameSDP,
"add the display of a set of discrete points as ball of radius 0.5.");
178 app.add_flag(
"--invertNormal,-n", invertNormal,
"invert face normal vectors.");
179 app.add_flag(
"--drawVertex,-v", drawVertex,
"draw the vertex of the mesh");
181 app.get_formatter()->column_width(40);
182 CLI11_PARSE(app, argc, argv);
185 DGtal::Color vFieldLineColor = DGtal::Color::Red;
186 if (customLineColor.size() == 4)
188 vFieldLineColor.setRGBi(customLineColor[0], customLineColor[1], customLineColor[2], 255);
191 if (customColorMesh.size() != 0)
193 if (customColorMesh.size() < 4)
195 trace.error() <<
"colors specification should contain R,G,B and Alpha values" << std::endl;
199 if (customColorSDP.size() == 4)
201 sdpColorR = customColorSDP[0];
202 sdpColorG = customColorSDP[1];
203 sdpColorB = customColorSDP[2];
204 sdpColorA = customColorSDP[3];
208 s <<
"meshViewer - DGtalTools: ";
209 string name = inputFileNames[0].substr(inputFileNames[0].find_last_of(
"/")+1,inputFileNames[0].size()) ;
210 s <<
" " << name <<
" (W key to display settings)";
211 polyscope::options::programName = s.str();
212 polyscope::options::buildGui=
false;
213 polyscope::options::groundPlaneMode = polyscope::GroundPlaneMode::None;
217 PolyscopeViewer viewer;
219 viewer.allowReuseList =
true;
220 trace.info() <<
"Importing mesh... ";
222 std::vector<Mesh<DGtal::Z3i::RealPoint>> vectMesh;
223 for (
unsigned int i = 0; i < inputFileNames.size(); i++)
225 Mesh<DGtal::Z3i::RealPoint> aMesh(customColorMesh.size() != 4 && customColorMesh.size() != 8);
226 aMesh << inputFileNames[i];
228 if (aMesh.isStoringFaceColors() && customColorMesh.size() >= 4)
230 if (i * 8 < customColorMesh.size())
232 meshColorR = customColorMesh[i * 8];
234 if (i * 8 + 1 < customColorMesh.size())
236 meshColorG = customColorMesh[i * 8 + 1];
238 if (i * 8 + 2 < customColorMesh.size())
240 meshColorB = customColorMesh[i * 8 + 2];
242 if (i * 8 + 3 < customColorMesh.size())
244 meshColorA = customColorMesh[i * 8 + 3];
246 for (
unsigned int j = 0; j < aMesh.nbFaces(); j++)
248 aMesh.setFaceColor(j, Color(meshColorR, meshColorG, meshColorB, meshColorA));
251 else if (customAlphaMesh.size() > 0)
253 for (
unsigned int j = 0; j < aMesh.nbFaces(); j++)
255 auto c = aMesh.getFaceColor(j);
256 aMesh.setFaceColor(j, Color(c.red(), c.green(), c.blue(), customAlphaMesh.at(i < customAlphaMesh.size() ? i : 0)));
260 vectMesh.push_back(aMesh);
263 bool import = vectMesh.size() == inputFileNames.size();
266 trace.info() <<
"File import failed. " << std::endl;
270 trace.info() <<
"[done]. " << std::endl;
271 if (filenameSDP !=
"")
273 if (customAlphaMesh.size() > 0)
275 trace.info() <<
"New meshViewer" << std::endl;
276 auto vOrigins = PointListReader<PointVector<1, DGtal::int32_t>>::getPolygonsFromFile(filenameSDP);
277 viewer << Color(sdpColorR, sdpColorG, sdpColorB, sdpColorA);
278 for (
auto l : vOrigins)
280 DGtal::Z3i::Point pt(l[0][0], l[1][0], l[2][0]);
281 DGtal::Color cl(l[3][0], l[4][0], l[5][0], sdpColorA);
282 viewer.drawColor(cl);
288 vector<Z3i::RealPoint> vectPoints;
289 vectPoints = PointListReader<Z3i::RealPoint>::getPointsFromFile(filenameSDP);
290 viewer << Color(sdpColorR, sdpColorG, sdpColorB, sdpColorA);
291 for (
unsigned int i = 0; i < vectPoints.size(); i++)
293 viewer.drawBall(vectPoints.at(i));
299 for (
unsigned int i = 0; i < vectMesh.size(); i++)
301 vectMesh[i].invertVertexFaceOrder();
305 for (
unsigned int i = 0; i < vectMesh.size(); i++)
307 if (i * 8 < customColorMesh.size())
309 meshColorR = customColorMesh[i * 8];
311 if (i * 8 + 1 < customColorMesh.size())
313 meshColorG = customColorMesh[i * 8 + 1];
315 if (i * 8 + 2 < customColorMesh.size())
317 meshColorB = customColorMesh[i * 8 + 2];
319 if (i * 8 + 3 < customColorMesh.size())
321 meshColorA = customColorMesh[i * 8 + 3];
323 if (i * 8 + 4 < customColorMesh.size())
325 meshColorALine = customColorMesh[i * 8 + 4];
327 if (i * 8 + 5 < customColorMesh.size())
329 meshColorBLine = customColorMesh[i * 8 + 5];
331 if (i * 8 + 6 < customColorMesh.size())
333 meshColorRLine = customColorMesh[i * 8 + 6];
335 if (i * 8 + 7 < customColorMesh.size())
337 meshColorALine = customColorMesh[i * 8 + 7];
340 viewer << Color(meshColorR, meshColorG, meshColorB, meshColorA);
341 viewer << vectMesh[i];
346 for (
unsigned int i = 0; i < vectMesh.size(); i++)
348 for (Mesh<DGtal::Z3i::RealPoint>::VertexStorage::const_iterator it = vectMesh[i].vertexBegin();
349 it != vectMesh[i].vertexEnd(); ++it)
351 DGtal::Z3i::Point pt;
360 if (displayVectorField !=
"")
362 std::vector<unsigned int> vectFieldIndices1 = {vectFieldIndices[0], vectFieldIndices[1], vectFieldIndices[2]};
363 std::vector<unsigned int> vectFieldIndices2 = {vectFieldIndices[3], vectFieldIndices[4], vectFieldIndices[5]};
364 std::vector<DGtal::Z3i::RealPoint> vectPt1 = PointListReader<DGtal::Z3i::RealPoint>::getPointsFromFile(displayVectorField, vectFieldIndices1);
365 std::vector<DGtal::Z3i::RealPoint> vectPt2 = PointListReader<DGtal::Z3i::RealPoint>::getPointsFromFile(displayVectorField, vectFieldIndices2);
366 for (
unsigned int i = 0; i < vectPt1.size(); i++)
368 viewer.drawColor(vFieldLineColor);
369 viewer.drawLine(vectPt1[i], vectPt2[i]);
372 unsigned int nbVertex = 0;
373 unsigned int nbFaces = 0;
374 for (
auto const &m : vectMesh)
376 nbVertex += m.nbVertex();
377 nbFaces += m.nbFaces();
380 ss <<
"# faces: " << std::fixed << nbFaces <<
" #vertex: " << nbVertex;
381 trace.info() <<
"[display ready]" << std::endl;
382 polyscope::state::userCallback = myCallback;