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"
51 #include <boost/program_options/options_description.hpp>
52 #include <boost/program_options/parsers.hpp>
53 #include <boost/program_options/variables_map.hpp>
58 using namespace DGtal;
62 namespace po = boost::program_options;
116 template <
typename Space = DGtal::Z3i::Space,
typename KSpace = DGtal::Z3i::KSpace>
127 QObject::connect(
this, SIGNAL(drawFinished(
bool)),
this, SLOT(saveSnapshot(
bool)));
134 template <
typename Po
int>
136 getBoundingUpperAndLowerPoint(
const std::vector<Point> &vectorPt,
Point &ptLower,
Point &ptUpper){
137 for(
unsigned int i =1; i<vectorPt.size(); i++){
138 if(vectorPt.at(i)[0] < ptLower[0]){
139 ptLower[0] = vectorPt.at(i)[0];
141 if(vectorPt.at(i)[1] < ptLower[1]){
142 ptLower[1] = vectorPt.at(i)[1];
144 if(vectorPt.at(i)[2] < ptLower[2]){
145 ptLower[2] =vectorPt.at(i)[2];
147 if(vectorPt.at(i)[0] < ptLower[0]){
148 ptLower[0] = vectorPt.at(i)[0];
150 if(vectorPt.at(i)[1] < ptLower[1]){
151 ptLower[1] = vectorPt.at(i)[1];
153 if(vectorPt.at(i)[2] < ptLower[2]){
154 ptLower[2] =vectorPt.at(i)[2];
160 int main(
int argc,
char** argv )
167 po::options_description general_opt(
"Allowed options are: ");
168 general_opt.add_options()
169 (
"help,h",
"display this message")
170 (
"input,i", po::value<std::string>(),
"input file: sdp (sequence of discrete points with attribute)" )
171 (
"noWindows,n",
"Don't display Viewer windows." )
172 (
"doSnapShotAndExit,d", po::value<std::string>(),
"save display snapshot into file." )
173 (
"fixMaxColorValue", po::value<double>(),
"fix the maximal color value for the scale error display (else the scale is set from the maximal value)" )
174 (
"fixMinColorValue", po::value<double>(),
"fix the minimal color value for the scale error display (else the scale is set from the minimal value)" )
175 (
"labelIndex", po::value<unsigned int>(),
"set the index of the label (by default set to 3) " )
176 (
"SDPindex", po::value<std::vector <unsigned int> >()->multitoken(),
"specify the sdp index (by default 0,1,2).");
180 bool cannotStart=
false;
181 po::variables_map vm;
185 po::store(po::parse_command_line(argc, argv, general_opt), vm);
186 }
catch(
const std::exception& ex){
188 trace.
error()<<
"Error checking program options: "<< ex.what()<< endl;
191 if(parseOK && ! vm.count(
"input"))
193 trace.
error() <<
" The input file name was not defined" << endl;
198 if( !parseOK || cannotStart || vm.count(
"help")||argc<=1)
200 trace.
info() <<
"Usage: " << argv[0] <<
" [input]\n"
201 <<
"Display surfel data from SDP file with color attributes given as scalar interpreted as color. "
202 << general_opt <<
"\n";
206 string inputFilename = vm[
"input"].as<std::string>();
209 std::vector<Point4D> surfelAndScalarInput;
213 if(vm.count(
"SDPindex")) {
214 std::vector<unsigned int > vectIndex = vm[
"SDPindex"].as<std::vector<unsigned int > >();
215 if(vectIndex.size()!=4){
216 trace.
error() <<
"you need to specify the three indexes of vertex." << std::endl;
225 Point4D ptLower = surfelAndScalarInput.at(0);
226 Point4D ptUpper = surfelAndScalarInput.at(0);
227 getBoundingUpperAndLowerPoint(surfelAndScalarInput, ptLower, ptUpper);
230 K.
init(
Z3i::Point(2*ptLower[0]+1, 2*ptLower[1]+1, 2*ptLower[2]+1),
231 Z3i::Point(2*ptUpper[0]+1, 2*ptUpper[1]+1, 2*ptUpper[2]+1),
true);
234 std::vector<Cell> vectSurfelsInput;
237 for(
unsigned int i =0; i<surfelAndScalarInput.size(); i++){
238 Point4D pt4d = surfelAndScalarInput.at(i);
240 vectSurfelsInput.push_back(c);
245 std::vector<unsigned int> vectIndexMinToReference;
251 QApplication application(argc,argv);
252 typedef ViewerSnap<>
Viewer;
254 Viewer viewer(K, vm.count(
"doSnapShotAndExit"));
255 if(vm.count(
"doSnapShotAndExit")){
256 viewer.setSnapshotFileName(QString(vm[
"doSnapShotAndExit"].as<std::string>().c_str()));
258 viewer.setWindowTitle(
"3dCompSurfel Viewer");
260 viewer.restoreStateFromFile();
262 double minScalarVal=surfelAndScalarInput.at(0)[3];
263 double maxScalarVal=surfelAndScalarInput.at(0)[3];
265 for(
unsigned int i=1; i <surfelAndScalarInput.size(); i++){
266 double scalVal = surfelAndScalarInput.at(i)[3];
267 if(scalVal < minScalarVal){
268 minScalarVal = scalVal;
270 if(scalVal > maxScalarVal){
271 maxScalarVal = scalVal;
274 if(vm.count(
"fixMaxColorValue")){
275 maxScalarVal = vm[
"fixMaxColorValue"].as<
double>();
277 if(vm.count(
"fixMinColorValue")){
278 minScalarVal = vm[
"fixMinColorValue"].as<
double>();
282 gradientColorMap.addColor(
Color(255,0,0,100 ) );
283 gradientColorMap.addColor(
Color(0,255,0,100 ) );
284 gradientColorMap.addColor(
Color(0,0,255,100 ) );
286 bool useGrad = minScalarVal!=maxScalarVal;
288 viewer <<
SetMode3D(vectSurfelsInput.at(0).className(),
"Basic");
289 for(
unsigned int i=0; i <surfelAndScalarInput.size(); i++){
290 double valInput = surfelAndScalarInput.at(i)[3];
292 viewer.setFillColor(gradientColorMap(valInput));
294 viewer.setFillColor(Color::White);
296 viewer << vectSurfelsInput.at(i);
302 if(vm.count(
"doSnapShotAndExit")){
304 std::string name = vm[
"doSnapShotAndExit"].as<std::string>();
305 std::string extension = name.substr(name.find_last_of(
".") + 1);
306 std::string basename = name.substr(0, name.find_last_of(
"."));
307 for(
int i=0; i< viewer.snapshotCounter()-1; i++){
309 s << basename <<
"-"<< setfill(
'0') << setw(4)<< i <<
"." << extension;
310 trace.
info() <<
"erase temp file: " << s.str() << std::endl;
311 remove(s.str().c_str());
314 s << basename <<
"-"<< setfill(
'0') << setw(4)<< viewer.snapshotCounter()-1 <<
"." << extension;
315 rename(s.str().c_str(), name.c_str());
319 if(vm.count(
"noWindows")){
322 return application.exec();
Cell uCell(const PreCell &c) const
bool init(const Point &lower, const Point &upper, bool isClosed)
Trace trace(traceWriterTerm)
typename Self::Point Point