DGtalTools 2.1.0
Loading...
Searching...
No Matches
3dDisplaySurfelData.cpp
1
29
30#include <iostream>
31#include <sstream>
32#include <stdio.h>
33
34#include "DGtal/base/Common.h"
35#include "DGtal/helpers/StdDefs.h"
36#include "DGtal/io/viewers/PolyscopeViewer.h"
37#include "DGtal/io/readers/PointListReader.h"
38#include "DGtal/io/readers/MeshReader.h"
39#include "DGtal/io/colormaps/GradientColorMap.h"
40
41#include "DGtal/topology/helpers/Surfaces.h"
42#include "DGtal/topology/SurfelAdjacency.h"
43#include "DGtal/topology/CanonicCellEmbedder.h"
44#include "DGtal/math/Statistic.h"
45
46#include "DGtal/io/Color.h"
47#include "DGtal/io/colormaps/GradientColorMap.h"
48#include "DGtal/io/readers/GenericReader.h"
49
50#include "CLI11.hpp"
51
52#include <limits>
53
54using namespace std;
55using namespace DGtal;
56using namespace Z3i;
57
58
111template < typename Point>
112void
113getBoundingUpperAndLowerPoint(const std::vector<Point> &vectorPt, Point &ptLower, Point &ptUpper){
114 for(unsigned int i =1; i<vectorPt.size(); i++)
115 {
116 if(vectorPt.at(i)[0] < ptLower[0])
117 {
118 ptLower[0] = vectorPt.at(i)[0];
119 }
120 if(vectorPt.at(i)[1] < ptLower[1])
121 {
122 ptLower[1] = vectorPt.at(i)[1];
123 }
124 if(vectorPt.at(i)[2] < ptLower[2])
125 {
126 ptLower[2] =vectorPt.at(i)[2];
127 }
128 if(vectorPt.at(i)[0] > ptUpper[0])
129 {
130 ptUpper[0] = vectorPt.at(i)[0];
131 }
132 if(vectorPt.at(i)[1] > ptUpper[1])
133 {
134 ptUpper[1] = vectorPt.at(i)[1];
135 }
136 if(vectorPt.at(i)[2] > ptUpper[2])
137 {
138 ptUpper[2] =vectorPt.at(i)[2];
139 }
140 }
141}
142
143
144int main( int argc, char** argv )
145{
146 typedef PointVector<4, double> Point4D;
147 typedef PointVector<1, int> Point1D;
148
149 // parse command line using CLI ----------------------------------------------
150 CLI::App app;
151 std::string inputFileName;
152 unsigned int labelIndex;
153 std::vector<unsigned int> vectSDPindex {0, 1, 2, 3};
154
155 app.description("Display surfel data from SDP file with color attributes given as scalar interpreted as color. \n Example of use: \n First you have to generate a file containing a set of surfels with, for instance, their associated curvature values: \n 3dCurvatureViewer -i $DGtal/examples/samples/cat10.vol -r 3 --exportOnly -d curvatureCat10R3.dat \n Then, we can use this tool to display the set of surfel with their associated values: 3dDisplaySurfelData -i curvatureCat10R3.dat");
156 app.add_option("-i,--input,1", inputFileName, "input file: sdp (sequence of discrete points with attribute)" )
157 ->required()
158 ->check(CLI::ExistingFile);
159 app.add_option("--labelIndex", labelIndex , "set the index of the label.");
160 app.add_option("--SDPindex", vectSDPindex, "specify the sdp index.");
161
162 app.get_formatter()->column_width(40);
163 CLI11_PARSE(app, argc, argv);
164 // END parse command line using CLI ----------------------------------------------
165
166 std::vector<Point4D> surfelAndScalarInput;
167 Z3i::KSpace K;
168
169 surfelAndScalarInput = PointListReader<Point4D>::getPointsFromFile(inputFileName, vectSDPindex);
170
171 Point4D ptLower = surfelAndScalarInput.at(0);
172 Point4D ptUpper = surfelAndScalarInput.at(0);
173 getBoundingUpperAndLowerPoint(surfelAndScalarInput, ptLower, ptUpper);
174
175 K.init(Z3i::Point(2*ptLower[0]+1, 2*ptLower[1]+1, 2*ptLower[2]+1),
176 Z3i::Point(2*ptUpper[0]+1, 2*ptUpper[1]+1, 2*ptUpper[2]+1), true);
177
178 std::vector<Cell> vectSurfelsInput;
179
180 // Construction of the set of surfels
181 for(unsigned int i =0; i<surfelAndScalarInput.size(); i++){
182 Point4D pt4d = surfelAndScalarInput.at(i);
183 Cell c = K.uCell(Z3i::Point(pt4d[0], pt4d[1], pt4d[2]));
184 vectSurfelsInput.push_back(c);
185 }
186
187 CanonicCellEmbedder<KSpace> embeder(K);
188 std::vector<unsigned int> vectIndexMinToReference;
189
190 //-------------------------
191 // Displaying input with color given from scalar values
192
193 stringstream s;
194 s << "3dDisplaySurfelData - DGtalTools";
195
196 polyscope::options::programName = s.str();
197 polyscope::view::setNavigateStyle(polyscope::NavigateStyle::Free);
198
199 typedef PolyscopeViewer<> Viewer;
200
201 Viewer viewer(K);
202
203 for(unsigned int i=0; i <surfelAndScalarInput.size(); i++)
204 {
205 double valInput = surfelAndScalarInput.at(i)[3];
206 viewer << WithQuantity(vectSurfelsInput.at(i), "value", valInput);
207 }
208
209 viewer.show();
210 return 0;
211}
Definition ATu0v1.h:57