31 #include <QGLViewer/qglviewer.h>
34 #include "DGtal/base/Common.h"
35 #include "DGtal/helpers/StdDefs.h"
36 #include "DGtal/io/viewers/Viewer3D.h"
37 #include "DGtal/io/DrawWithDisplay3DModifier.h"
38 #include "DGtal/io/readers/PointListReader.h"
39 #include "DGtal/io/readers/MeshReader.h"
40 #include "DGtal/io/colormaps/GradientColorMap.h"
42 #include "DGtal/topology/helpers/Surfaces.h"
43 #include "DGtal/topology/SurfelAdjacency.h"
44 #include "DGtal/topology/CanonicCellEmbedder.h"
45 #include "DGtal/math/Statistic.h"
47 #include "DGtal/io/Color.h"
48 #include "DGtal/io/colormaps/GradientColorMap.h"
49 #include "DGtal/io/readers/GenericReader.h"
56 using namespace DGtal;
112 template <
typename Space = DGtal::Z3i::Space,
typename KSpace = DGtal::Z3i::KSpace>
113 struct ViewerSnap: DGtal::Viewer3D <Space, KSpace>
116 ViewerSnap(
const KSpace &KSEmb,
bool saveSnap): Viewer3D<Space, KSpace>(KSEmb), mySaveSnap(saveSnap){
121 DGtal::Viewer3D<>::init();
124 QObject::connect(
this, SIGNAL(drawFinished(
bool)),
this, SLOT(saveSnapshot(
bool)));
131 template <
typename Po
int>
133 getBoundingUpperAndLowerPoint(
const std::vector<Point> &vectorPt, Point &ptLower, Point &ptUpper){
134 for(
unsigned int i =1; i<vectorPt.size(); i++)
136 if(vectorPt.at(i)[0] < ptLower[0])
138 ptLower[0] = vectorPt.at(i)[0];
140 if(vectorPt.at(i)[1] < ptLower[1])
142 ptLower[1] = vectorPt.at(i)[1];
144 if(vectorPt.at(i)[2] < ptLower[2])
146 ptLower[2] =vectorPt.at(i)[2];
148 if(vectorPt.at(i)[0] < ptLower[0])
150 ptLower[0] = vectorPt.at(i)[0];
152 if(vectorPt.at(i)[1] < ptLower[1])
154 ptLower[1] = vectorPt.at(i)[1];
156 if(vectorPt.at(i)[2] < ptLower[2])
158 ptLower[2] =vectorPt.at(i)[2];
164 int main(
int argc,
char** argv )
166 typedef PointVector<4, double> Point4D;
167 typedef PointVector<1, int> Point1D;
171 std::string inputFileName;
172 std::string doSnapShotName;
173 bool noWindows {
false};
176 unsigned int labelIndex;
177 std::vector<unsigned int> vectSDPindex {0, 1, 2};
179 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");
180 app.add_option(
"-i,--input,1", inputFileName,
"input file: sdp (sequence of discrete points with attribute)" )
182 ->check(CLI::ExistingFile);
183 app.add_flag(
"--noWindows,-n",noWindows,
"Don't display Viewer windows.");
184 app.add_option(
"--doSnapShotAndExit,-d", doSnapShotName,
"save display snapshot into file.");
185 auto fixMaxOption = app.add_option(
"--fixMaxColorValue,-M", maxScalarVal,
"fix manually the maximal color value for the scale error display (else the scale is set from the maximal value)");
186 auto fixMinOption = app.add_option(
"--fixMinColorValue,-m", minScalarVal,
"fix manually the maximal color value for the scale error display (else the scale is set from the minimal value)");
187 app.add_option(
"--labelIndex", labelIndex ,
"set the index of the label.",
true);
188 app.add_option(
"--SDPindex", vectSDPindex,
"specify the sdp index.",
true);
190 app.get_formatter()->column_width(40);
191 CLI11_PARSE(app, argc, argv);
194 std::vector<Point4D> surfelAndScalarInput;
197 surfelAndScalarInput = PointListReader<Point4D>::getPointsFromFile(inputFileName, vectSDPindex);
199 Point4D ptLower = surfelAndScalarInput.at(0);
200 Point4D ptUpper = surfelAndScalarInput.at(0);
201 getBoundingUpperAndLowerPoint(surfelAndScalarInput, ptLower, ptUpper);
203 K.init(Z3i::Point(2*ptLower[0]+1, 2*ptLower[1]+1, 2*ptLower[2]+1),
204 Z3i::Point(2*ptUpper[0]+1, 2*ptUpper[1]+1, 2*ptUpper[2]+1),
true);
207 std::vector<Cell> vectSurfelsInput;
210 for(
unsigned int i =0; i<surfelAndScalarInput.size(); i++){
211 Point4D pt4d = surfelAndScalarInput.at(i);
212 Cell c = K.uCell(Z3i::Point(pt4d[0], pt4d[1], pt4d[2]));
213 vectSurfelsInput.push_back(c);
216 CanonicCellEmbedder<KSpace> embeder(K);
217 std::vector<unsigned int> vectIndexMinToReference;
222 QApplication application(argc,argv);
223 typedef ViewerSnap<> Viewer;
225 Viewer viewer(K, doSnapShotName !=
"");
226 if(doSnapShotName !=
"")
228 viewer.setSnapshotFileName(QString(doSnapShotName.c_str()));
230 viewer.setWindowTitle(
"3dCompSurfel Viewer");
232 viewer.restoreStateFromFile();
234 if( fixMinOption->count() == 0 )
236 minScalarVal=surfelAndScalarInput.at(0)[3];
238 if( fixMaxOption->count() == 0 )
240 maxScalarVal=surfelAndScalarInput.at(0)[3];
243 if( fixMinOption->count() == 0 || fixMaxOption->count() == 0)
245 for(
unsigned int i=1; i <surfelAndScalarInput.size(); i++)
247 double scalVal = surfelAndScalarInput.at(i)[3];
248 if(scalVal < minScalarVal && fixMinOption->count() == 0)
250 minScalarVal = scalVal;
252 if(scalVal > maxScalarVal && fixMaxOption->count() == 0)
254 maxScalarVal = scalVal;
259 GradientColorMap<double> gradientColorMap( minScalarVal, maxScalarVal );
260 gradientColorMap.addColor( Color(255,0,0,100 ) );
261 gradientColorMap.addColor( Color(0,255,0,100 ) );
262 gradientColorMap.addColor( Color(0,0,255,100 ) );
264 bool useGrad = minScalarVal!=maxScalarVal;
266 viewer << SetMode3D(vectSurfelsInput.at(0).className(),
"Basic");
267 for(
unsigned int i=0; i <surfelAndScalarInput.size(); i++)
269 double valInput = surfelAndScalarInput.at(i)[3];
272 viewer.setFillColor(gradientColorMap(valInput));
275 viewer.setFillColor(Color::White);
277 viewer << vectSurfelsInput.at(i);
282 viewer << Viewer::updateDisplay;
283 if(doSnapShotName !=
"")
286 std::string name = doSnapShotName;
287 std::string extension = name.substr(name.find_last_of(
".") + 1);
288 std::string basename = name.substr(0, name.find_last_of(
"."));
289 for(
int i=0; i< viewer.snapshotCounter()-1; i++){
291 s << basename <<
"-"<< setfill(
'0') << setw(4)<< i <<
"." << extension;
292 trace.info() <<
"erase temp file: " << s.str() << std::endl;
293 remove(s.str().c_str());
296 s << basename <<
"-"<< setfill(
'0') << setw(4)<< viewer.snapshotCounter()-1 <<
"." << extension;
297 rename(s.str().c_str(), name.c_str());
307 return application.exec();