Beispiel #1
0
int main( int argc, char** argv )
{

 QApplication application(argc,argv);
 Viewer3D<> viewer;
 viewer.setWindowTitle("simpleViewer");
 viewer.show();
 trace.beginBlock ( "Testing Polygon 3D display in Viewer3D" );
 std::vector<Z3i::RealPoint> polyg1;

 polyg1.push_back(Z3i::RealPoint(0,0,0));
 polyg1.push_back(Z3i::RealPoint(0,1,0));
 polyg1.push_back(Z3i::RealPoint(1,1,0));

 viewer.addPolygon(polyg1);

 viewer.createNewPolygonList("hop");

 std::vector<Z3i::RealPoint> polyg2;

 polyg2.push_back(Z3i::RealPoint(0,10,0));
 polyg2.push_back(Z3i::RealPoint(0,11,0));
 polyg2.push_back(Z3i::RealPoint(11,11,0));

 viewer.addPolygon(polyg2);

 viewer << Viewer3D<>::updateDisplay;

 bool res = application.exec();
 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
 trace.endBlock();
 return res ? 0 : 1;


}
Beispiel #2
0
int main( int argc, char** argv )
{
  typedef DGtal::ImageContainerBySTLVector< DGtal::Z2i::Domain, unsigned char>  imageNG;
  typedef DGtal::ImageContainerBySTLVector< DGtal::Z2i::Domain, unsigned int>  imageCol;

 QApplication application(argc,argv);
 Viewer3D<> viewer;
 viewer.setWindowTitle("simpleViewer");
 viewer.show();
 
 
 Point p1( 0, 0, 0 );
 Point p2( 125, 188, 0 );
 Point p3( 30, 30, 30 );

 std::string filename =  testPath + "samples/church-small.pgm";
 std::string filename3 =  testPath + "samples/color64.ppm";
 
 imageNG image = DGtal::PGMReader<imageNG>::importPGM(filename); 
 imageNG image2 = DGtal::GenericReader<imageNG>::import(filename); 
 imageCol image3 = DGtal::GenericReader<imageCol>::import(filename3); 
 
 viewer << DGtal::AddTextureImage2DWithFunctor<imageNG,  hueFct , Z3i::Space, Z3i::KSpace>(image2, hueFct(), Viewer3D<>::RGBMode );
 viewer << image;
 viewer << DGtal::AddTextureImage2DWithFunctor<imageCol,  DefaultFunctor, Z3i::Space, Z3i::KSpace>(image3, DefaultFunctor(), Viewer3D<>::RGBMode );
 viewer << DGtal::UpdateImagePosition<Z3i::Space, Z3i::KSpace>(0, Viewer3D<>::xDirection,  50, 50, 50 );
 viewer << DGtal::UpdateImagePosition<Z3i::Space, Z3i::KSpace>(2, Viewer3D<>::yDirection,  0, 0, 0);
 
 viewer << SetMode3D( image.domain().className(), "BoundingBox" );
 viewer << image.domain();
 viewer << DGtal::Update2DDomainPosition<Z3i::Space, Z3i::KSpace>(0, Viewer3D<>::xDirection, 0, 0, 0);
 for(unsigned int i= 0; i< 10; i++){
   if(i%4==0){
     viewer << SetMode3D( image.className(), "" );
   }else if(i%4==1){
     viewer << SetMode3D( image.className(), "BoundingBox" );
   }else if(i%4==2){
     viewer << SetMode3D( image.className(), "Grid" );
   }else if(i%4==3){
     viewer << SetMode3D( image.className(), "InterGrid" );
   }
   viewer << image; 
   viewer << DGtal::UpdateImageData<imageNG>(i+3, image,  i*50, i*50, i*50);
 }


 viewer << p1 << p2 << p3;
 viewer << Viewer3D<>::updateDisplay;


 bool res = application.exec();
 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
 trace.endBlock();
 return res ? 0 : 1;


}
int main( int argc, char** argv )
{
  typedef DGtal::ImageContainerBySTLVector< DGtal::Z3i::Domain, unsigned char>  Image3D;

 QApplication application(argc,argv);
 Viewer3D<> viewer;
 viewer.setWindowTitle("simpleViewer");
 viewer.show();
 trace.beginBlock("Testing Viewer with display of 3D Image  "); 
 
 Point p1( 0, 0, 0 );
 Point p2( 125, 188, 0 );
 Point p3( 30, 30, 30 );
 
 std::string filename =  testPath + "samples/lobsterCroped.vol";
 viewer.setFillTransparency(150);
 Image3D image3d =  VolReader<Image3D>::importVol(filename); 
 viewer << SetMode3D(image3d.className(), "BoundingBox");
 viewer << DGtal::AddTextureImage3DWithFunctor<Image3D,  hueFct , Space, KSpace>(image3d, hueFct(),Viewer3D<>::RGBMode );
 viewer.setFillTransparency(255);
 // Extract some slice images:
 // Get the 2D domain of the slice:
 DGtal::Projector<DGtal::Z2i::Space>  invFunctor; invFunctor.initRemoveOneDim(2);
 DGtal::Z2i::Domain domain2D(invFunctor(image3d.domain().lowerBound()),
			     invFunctor(image3d.domain().upperBound()));
  
  typedef DGtal::ConstImageAdapter<Image3D, DGtal::Z2i::Domain,  DGtal::Projector< Z3i::Space>,
				    Image3D::Value,  DGtal::DefaultFunctor >  SliceImageAdapter;
  DGtal::DefaultFunctor idV;
  DGtal::Projector<DGtal::Z3i::Space> aSliceFunctorZ(5); aSliceFunctorZ.initAddOneDim(2);
  SliceImageAdapter sliceImageZ(image3d, domain2D, aSliceFunctorZ, idV);

  viewer << sliceImageZ;
  viewer <<  DGtal::UpdateImagePosition<Space, KSpace>(6, Viewer3D<>::zDirection, 0.0, 0.0, -10.0);
 
 viewer << p1 << p2 << p3;
 viewer << Viewer3D<>::updateDisplay;


 bool res = application.exec();
 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
 trace.endBlock();
 return res ? 0 : 1;


}
int main( int argc, char** argv )
{
  
  typedef DGtal::ImageContainerBySTLVector< DGtal::Z3i::Domain, unsigned int>  Image3D;
  typedef DGtal::ConstImageAdapter<Image3D, Z2i::Domain, DGtal::Point2DEmbedderIn3D<DGtal::Z3i::Domain>,
                                   Image3D::Value,  DGtal::DefaultFunctor >  ImageAdapterExtractor;

 QApplication application(argc,argv);
 Viewer3D<> viewer;
 viewer.setWindowTitle("simpleViewer");
 viewer.show();
  
 trace.beginBlock("Testing Viewer with Image Embedder ");
 Point pcenter( 10, 20, 20 );
 Point pcenterImg( 10, 20, 20 );

 std::string filename =  testPath + "samples/cat10.pgm3d";
 Image3D image = DGtal::GenericReader<Image3D>::import(filename); 
 
 const int IMAGE_PATCH_WIDTH = 80;  
 // Setting the image domain of the resulting image to be displayed in 3D:
 DGtal::Z2i::Domain domainImage2D (DGtal::Z2i::Point(0,0), 
                                   DGtal::Z2i::Point(IMAGE_PATCH_WIDTH, IMAGE_PATCH_WIDTH)); 
  
 DGtal::Point2DEmbedderIn3D<DGtal::Z3i::Domain >  embedder(image.domain(), 
                                                           pcenterImg, Z3i::RealPoint(1, 1, 1), 
                                                           IMAGE_PATCH_WIDTH);
 DGtal::Point2DEmbedderIn3D<DGtal::Z3i::Domain >  embedder2(image.domain(), 
                                                           pcenterImg, Z3i::RealPoint(1, 0, 0), 
                                                           IMAGE_PATCH_WIDTH);
 DGtal::Point2DEmbedderIn3D<DGtal::Z3i::Domain >  embedder3(image.domain(), 
                                                           pcenterImg, Z3i::RealPoint(0, 1, 0 ), 
                                                           IMAGE_PATCH_WIDTH);
 DGtal::Point2DEmbedderIn3D<DGtal::Z3i::Domain >  embedder4(image.domain(), 
                                                           pcenterImg, Z3i::RealPoint(0, 0, 1 ), 
                                                           IMAGE_PATCH_WIDTH);
 
 DGtal::DefaultFunctor idV;
 ImageAdapterExtractor extractedImage(image, domainImage2D, embedder, idV);
 ImageAdapterExtractor extractedImage2(image, domainImage2D, embedder2, idV);
 ImageAdapterExtractor extractedImage3(image, domainImage2D, embedder3, idV);
 ImageAdapterExtractor extractedImage4(image, domainImage2D, embedder4, idV);

 viewer << extractedImage;
 viewer << extractedImage2;
 viewer << extractedImage3;
 viewer << extractedImage4;
 viewer << DGtal::UpdateImage3DEmbedding<Z3i::Space, Z3i::KSpace>(0, 
                                                                  embedder(Z2i::RealPoint(0,0),false),
                                                                  embedder(Z2i::RealPoint(IMAGE_PATCH_WIDTH,0),false),
                                                                  embedder(domainImage2D.upperBound(), false),
                                                                  embedder(Z2i::RealPoint(0, IMAGE_PATCH_WIDTH), false));
 viewer << DGtal::UpdateImage3DEmbedding<Z3i::Space, Z3i::KSpace>(1, 
                                                                  embedder2(Z2i::RealPoint(0,0),false),
                                                                  embedder2(Z2i::RealPoint(IMAGE_PATCH_WIDTH,0),false),
                                                                  embedder2(domainImage2D.upperBound(), false),
                                                                  embedder2(Z2i::RealPoint(0, IMAGE_PATCH_WIDTH), false));
 viewer << DGtal::UpdateImage3DEmbedding<Z3i::Space, Z3i::KSpace>(2, 
                                                                  embedder3(Z2i::RealPoint(0,0),false),
                                                                  embedder3(Z2i::RealPoint(IMAGE_PATCH_WIDTH,0),false),
                                                                  embedder3(domainImage2D.upperBound(), false),
                                                                  embedder3(Z2i::RealPoint(0, IMAGE_PATCH_WIDTH), false));
 viewer << DGtal::UpdateImage3DEmbedding<Z3i::Space, Z3i::KSpace>(3, 
                                                                  embedder4(Z2i::RealPoint(0,0),false),
                                                                  embedder4(Z2i::RealPoint(IMAGE_PATCH_WIDTH,0),false),
                                                                  embedder4(domainImage2D.upperBound(), false),
                                                                  embedder4(Z2i::RealPoint(0, IMAGE_PATCH_WIDTH), false));
 viewer.setFillColor(DGtal::Color(250,20,20,255));
 viewer << pcenter;
 
 

 viewer << Viewer3D<>::updateDisplay;

 
 bool res = application.exec();
 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
 trace.endBlock();
 return res ? 0 : 1;

}
int main( int argc, char** argv )
{
  
  std::string inputFilename = examplesPath + "samples/Al.100.vol";
  
  //------------
  typedef Z3i::Point Point;

  
  QApplication application(argc,argv);
  Viewer3D<> viewer;
  viewer.setWindowTitle("simpleViewer");
  viewer.show();


 
  //Default image selector = STLVector
  typedef ImageSelector<Z3i::Domain, unsigned char>::Type Image;
  Image image = VolReader<Image>::importVol( inputFilename );
  Z3i::Domain domain = image.domain();


  Image imageSeeds ( domain);
  for ( Image::Iterator it = imageSeeds.begin(), itend = imageSeeds.end();it != itend; ++it)
    (*it)=1;
  Z3i::Point p0(10,10,10);
  //imageSeeds.setValue(p0, 0 );
  randomSeeds(imageSeeds, 70, 0);


  //Distance transformation computation
  typedef SimpleThresholdForegroundPredicate<Image> Predicate;
  Predicate aPredicate(imageSeeds,0);

  typedef  DistanceTransformation<Z3i::Space,Predicate, Z3i::L2Metric> DTL2;
  DTL2 dtL2(&domain, &aPredicate, &Z3i::l2Metric);

  unsigned int min = 0;
  unsigned int max = 0;
  for(DTL2::ConstRange::ConstIterator it = dtL2.constRange().begin(), 
        itend=dtL2.constRange().end();
      it!=itend;
      ++it)
    {
      if(  (*it) < min )   
        min=(*it);
      if( (*it) > max ) 
        max=(*it);
    }
     
     
  GradientColorMap<long> gradient( 0,30);
  gradient.addColor(Color::Red);
  gradient.addColor(Color::Yellow);
  gradient.addColor(Color::Green);
  gradient.addColor(Color::Cyan);
  gradient.addColor(Color::Blue);
  gradient.addColor(Color::Magenta);
  gradient.addColor(Color::Red);  
 

  viewer << SetMode3D( (*(domain.begin())).className(), "Paving" );
  
  for(Z3i::Domain::ConstIterator it = domain.begin(), itend=domain.end();
      it!=itend;
      ++it){
   
    double valDist= dtL2( (*it) );     
    Color c= gradient(valDist);
   
    if(dtL2(*it)<=30 && image(*it)>0){
      viewer << CustomColors3D(Color((float)(c.red()), 
                                     (float)(c.green()),
                                     (float)(c.blue(),205)), 
                               Color((float)(c.red()), 
                                     (float)(c.green()),
                                     (float)(c.blue()),205));
      viewer << *it ;
    }     
  }
  viewer<< Viewer3D<>::updateDisplay;
 
  return application.exec();
}
int main( int argc, char** argv )
{

  // parse command line ----------------------------------------------
  po::options_description general_opt ( "Allowed options are: " );
  general_opt.add_options()
    ( "help,h", "display this message." )
    ( "input-file,i", po::value<std::string>(), "Input volumetric file (.vol, .pgm3d or p3d)" )
    ( "min,m", po::value<int>()->default_value( 0 ), "Minimum (excluded) value for threshold." )
    ( "max,M", po::value<int>()->default_value( 255 ), "Maximum (included) value for threshold." )
    ("fixedPoints", po::value<std::vector <int> >()->multitoken(), "defines the coordinates of points which should not be removed." );
  
  
  bool parseOK=true;
  po::variables_map vm;
  try{
    po::store(po::parse_command_line(argc, argv, general_opt), vm);  
  }catch(const std::exception& ex){
    parseOK=false;
    trace.info()<< "Error checking program options: "<< ex.what()<< endl;
  }
  po::notify ( vm );
  if ( !parseOK || vm.count ( "help" ) ||argc<=1 )
    {
      trace.info() << "Illustration of homotopic thinning of a 3d image file (vol,longvol,pgm3d...) with 3D viewer."<<std::endl
                   << std::endl << "Basic usage: "<<std::endl
                   << "\thomotopicThinning3d [options] --input-file <3dImageFileName>  {vol,longvol,pgm3d...} "<<std::endl
                   << general_opt << "\n"
                   << " Usage by forcing point to be left by the thinning: \n"
                   << "homotopicThinning3D --input-file ${DGtal}/examples/samples/Al.100.vol  --fixedPoints 56 35 5  56 61 5  57 91 38  58 8 38  45 50 97 \n";
      

        

      return 0;
    }

  //Parse options
  if ( ! ( vm.count ( "input-file" ) ) ) missingParam ( "--input" );
  std::string filename = vm["input-file"].as<std::string>();
  
  
  typedef ImageSelector < Z3i::Domain, unsigned char>::Type Image;
  Image image = GenericReader<Image>::import ( filename );

  trace.beginBlock("DT Computation");
  typedef IntervalForegroundPredicate<Image> Predicate;
  Predicate aPredicate(image, vm[ "min" ].as<int>(), vm[ "max" ].as<int>() );

  DistanceTransformation<Z3i::Space, Predicate , Z3i::L2Metric> dt(image.domain(),aPredicate, Z3i::L2Metric() );
  trace.endBlock();
  trace.info() <<image<<std::endl;

  // Domain creation from two bounding points.
  
  trace.beginBlock("Constructing Set");
  DigitalSet shape_set( image.domain() );
  DigitalSet fixedSet( image.domain() );
  
  // Get the optional fixed points
  if( vm.count("fixedPoints")){
    std::vector<int> vectC = vm["fixedPoints"].as<std::vector<int> >();
    if(vectC.size()%3==0){
      for( unsigned int i=0; i < vectC.size()-2; i=i+3){
        Z3i::Point pt(vectC.at(i), vectC.at(i+1), vectC.at(i+2));
        fixedSet.insertNew(pt);
      }
    }else{
      trace.error()<< " The coordinates should be 3d coordinates, ignoring fixedPoints option." << std::endl; 
    }
  }
  

  SetFromImage<DigitalSet>::append<Image>(shape_set, image,
                                          vm[ "min" ].as<int>(), vm[ "max" ].as<int>() );
  trace.info() << shape_set<<std::endl;
  trace.endBlock();
  
  
  
  
  trace.beginBlock("Computing skeleton");
  // (6,18), (18,6), (26,6) seem ok.
  // (6,26) gives sometimes weird results (but perhaps ok !).
  Object26_6 shape( dt26_6, shape_set );
  int nb_simple=0; 
  int layer = 1;
  std::queue<DigitalSet::Iterator> Q;
  do 
    {
      trace.info() << "Layer: "<< layer << std::endl;
      int nb=0;
      DigitalSet & S = shape.pointSet();
 
      trace.progressBar(0, (double)S.size());
      for ( DigitalSet::Iterator it = S.begin(); it != S.end(); ++it )
        {
	  if ( nb % 100 == 0 ) trace.progressBar((double)nb, (double)S.size()); 
          nb++;
	  if (dt( *it ) <= layer)
	    {
	      if ( shape.isSimple( *it ) )
		Q.push( it );
	    }
	}
      trace.progressBar( (double)S.size(), (double)S.size() );
      nb_simple = 0;
      while ( ! Q.empty() )
        {
          DigitalSet::Iterator it = Q.front();
          Q.pop();
          if ( shape.isSimple( *it ) && fixedSet.find(*it) == fixedSet.end() )
            {
              S.erase( *it );
              ++nb_simple;
            }
        }
      trace.info() << "Nb simple points : "<<nb_simple<< " " << std::endl;
      ++layer;
     }
  while ( nb_simple != 0 );
  trace.endBlock();
  
  DigitalSet & S = shape.pointSet();

  trace.info() << "Skeleton--> "<<S<<std::endl;

  // Display by using two different list to manage OpenGL transparency.
  QApplication application(argc,argv);
  Viewer3D<> viewer;
  viewer.setWindowTitle("simpleExample3DViewer");
  viewer.show();  
  
  viewer << SetMode3D( shape_set.className(), "Paving" );
  viewer << CustomColors3D(Color(25,25,255, 255), Color(25,25,255, 255));
  viewer << S ; 
  viewer << CustomColors3D(Color(255,25,255, 255), Color(255,25,255, 255));
  viewer << fixedSet;
  viewer << SetMode3D( shape_set.className(), "PavingTransp" );
  viewer << CustomColors3D(Color(250, 0,0, 25), Color(250, 0,0, 5));
  viewer << shape_set;

  viewer<< Viewer3D<>::updateDisplay;
   
  return application.exec();

}
Beispiel #7
0
int main( int argc, char** argv )
{

 QApplication application(argc,argv);
 Viewer3D<> viewer;
 viewer.setWindowTitle("simpleViewer");
 viewer.show();


 trace.beginBlock ( "Testing class for  Viewer3D" );


 Point p1( 14, 14, 14 );
 Point p2( 27, 27, 27 );
 Domain domain( p1, p2 );

 viewer << CustomColors3D(Color(20, 20, 20, 50),Color(20, 0,250,30));
 viewer << SetMode3D(domain.className(), "Grid");
 viewer << domain;

 DigitalSet shape_set( domain );
 Shapes<Domain>::addNorm1Ball( shape_set, Point( 13, 23, 13 ), 7 );
   viewer << CustomColors3D(Color(250, 200,0, 100),Color(250, 200,0, 50));

 viewer << shape_set ;
 DigitalSet shape_set2( domain );
 Shapes<Domain>::addNorm1Ball( shape_set2, Point( 24, 15, 12 ), 12 );
 viewer << shape_set2 ;

 DigitalSet shape_set3( domain );
 Shapes<Domain>::addNorm2Ball( shape_set3, Point( 11, 15, 12 ), 12 );
 viewer << CustomColors3D(Color(250, 20,0, 190),Color(220, 20,20, 250));
 viewer << shape_set3 ;




  Point pp1( -1, -1, -2 );
  Point pp2( 2, 2, 3 );


  Domain domain2( pp1, pp2 );
  Point pp3( 1, 1, 1 );
  Point pp4( 2, -1, 5 );
  Point pp5( -1, 2, 3 );
  Point pp6( 0, 0, 0 );
  Point pp0( 0, 2, 1 );

  //viewer<< m;
  viewer <<  SetMode3D( pp1.className(), "Paving" );
  viewer << pp1 << pp2 << pp3;

  //viewer <<  SetMode3D( pp1.className(), "Grid" );
  viewer << CustomColors3D(Color(250, 0,0),Color(250, 0,0));
  viewer <<  SetMode3D( pp1.className(), "PavingWired" );
  viewer << pp4 << pp5 ;
  viewer <<  SetMode3D( pp1.className(), "Both" );
  viewer << CustomColors3D(Color(250, 200,0, 100),Color(250, 0,0, 100));
  viewer << pp6;
  viewer << CustomColors3D(Color(250, 200,0, 100),Color(250, 200,0, 20));
  viewer << pp0;


  viewer << SetMode3D(domain.className(), "Paving");
  viewer << domain2 << Display3D<Space, KSpace>::updateDisplay;


 bool res = application.exec();
 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
 trace.endBlock();
 return res ? 0 : 1;


}
int main( int argc, char** argv )
{

  // parse command line ----------------------------------------------
  po::options_description general_opt ( "Allowed options are: " );
  general_opt.add_options()
    ( "help,h", "display this message." )
    ( "input,i", po::value<std::string>(), "Input vol file." );
    bool parseOK=true;
  po::variables_map vm;
  try{
    po::store(po::parse_command_line(argc, argv, general_opt), vm);  
  }catch(const std::exception& ex){
    parseOK=false;
    trace.info()<< "Error checking program options: "<< ex.what()<< endl;
  }
  po::notify ( vm );
  if ( !parseOK || vm.count ( "help" ) ||argc<=1 )
    {
      trace.info() << "Illustration of homotopic thinning of a vol file with 3D viewer."<<std::endl
                   << std::endl << "Basic usage: "<<std::endl
                   << "\thomotopicThinning3d [options] --input <volFileName>"<<std::endl
                   << general_opt << "\n";
      return 0;
    }

  //Parse options
  if ( ! ( vm.count ( "input" ) ) ) missingParam ( "--input" );
  std::string filename = vm["input"].as<std::string>();
  
  
  typedef ImageSelector < Z3i::Domain, unsigned char>::Type Image;
  Image image = VolReader<Image>::importVol ( filename );

  trace.beginBlock("DT Computation");
  typedef  DistanceTransformation<Image, 0> DTL2;
  DTL2 dtL2;
  
  DTL2::OutputImage resultL2 = dtL2.compute ( image );
  trace.endBlock();
  trace.info() <<image<<std::endl;

  // Domain cretation from two bounding points.
  Point c( 0, 0, 0 );
  Point p1( -50, -50, -50 );
  Point p2( 50, 50, 50 );
  Domain domain( p1, p2 );
  
  trace.beginBlock("Constructing Set");
  DigitalSet shape_set( domain );
  SetPredicate<DigitalSet> set3dPredicate( shape_set );
  SetFromImage<DigitalSet>::append<Image>(shape_set, image,
                                          0, 255);
  trace.info() << shape_set<<std::endl;
  trace.endBlock();

  trace.beginBlock("Computing skeleton");
  Object26_6 shape( dt26_6, shape_set );
  int nb_simple=0; 
  int layer = 1;
  std::queue<DigitalSet::Iterator> Q;
  do 
    {
      trace.info() << "Layer: "<< layer << std::endl;
      int nb=0;
      DigitalSet & S = shape.pointSet();
 
      for ( DigitalSet::Iterator it = S.begin(); it != S.end(); ++it )
        {
	  trace.progressBar((double)nb, (double)S.size()); 
	  trace.info() << nb<<" "; nb++;
	  if (resultL2( *it ) <= layer*layer)
	    {
	      if ( shape.isSimple( *it ) )
		Q.push( it );
	    }
	}
      nb_simple = 0;
      while ( ! Q.empty() )
        {
          DigitalSet::Iterator it = Q.front();
          Q.pop();
          if ( shape.isSimple( *it ) )
            {
              S.erase( *it );
              ++nb_simple;
            }
        }
      trace.info() << "Nb simple points : "<<nb_simple<<std::endl;
      ++layer;
     }
  while ( nb_simple != 0 );
  trace.endBlock();
  
  DigitalSet & S = shape.pointSet();

  trace.info() << "Skeleton--> "<<S<<std::endl;

  // Display by using two different list to manage OpenGL transparency.
  QApplication application(argc,argv);
  Viewer3D viewer;
  viewer.setWindowTitle("simpleExample3DViewer");
  viewer.show();  
  
  viewer << SetMode3D( shape_set.className(), "Paving" );
  viewer << CustomColors3D(Color(25,25,255, 255), Color(25,25,255, 255));
  viewer << S ; 

  viewer << SetMode3D( shape_set.className(), "PavingTransp" );
  viewer << CustomColors3D(Color(250, 0,0, 25), Color(250, 0,0, 5));
  viewer << shape_set;

  viewer<< Viewer3D::updateDisplay;
   
  return application.exec();

}
int main( int argc, char** argv )
{
  
  std::string inputFilename = examplesPath + "samples/Al.100.vol";
  
 //------------

 typedef SpaceND<3> Space4Type;
 typedef HyperRectDomain<Space4Type> TDomain;

 typedef TDomain::Point Point;

  
 QApplication application(argc,argv);
 Viewer3D viewer;
 viewer.setWindowTitle("simpleViewer");
 viewer.show();


 
 //Default image selector = STLVector
 typedef ImageSelector<TDomain, unsigned char>::Type Image;
 Image image = VolReader<Image>::importVol( inputFilename );
 TDomain domain(image.lowerBound(), image.upperBound());


 Image imageSeeds (image.lowerBound(), image.upperBound());
 for ( Image::Iterator it = imageSeeds.begin(), itend = imageSeeds.end();it != itend; ++it)
   (*it)=1;
 Z3i::Point p0(10,10,10);
 //imageSeeds.setValue(p0, 0 );
 randomSeeds(imageSeeds, 70, 0);


 //Distance transformation computation
 typedef ImageSelector<TDomain, long int>::Type ImageLong;

 typedef  DistanceTransformation<Image, 2> DTL2;
 typedef  DistanceTransformation<Image, 0> DTLInf;
 typedef  DistanceTransformation<Image, 1> DTL1;
 
 DTL2 dtL2;
 DTLInf dtLinf;
 DTL1 dtL1;

 
 dtL1.checkTypesValidity ( imageSeeds );
 DTL1::OutputImage resultL1 = dtL1.compute ( imageSeeds );
  


 
 unsigned int min = 0;
 unsigned int max = 0;
 for(DTL1::OutputImage::ConstIterator it = resultL1.begin(), itend=resultL1.end();
     it!=itend;
     ++it)
   {
     if(  (*it) < min )   
       min=(*it);
     if( (*it) > max ) 
       max=(*it);
   }
     
     
  GradientColorMap<long> gradient( 0,30);
  gradient.addColor(Color::Red);
  gradient.addColor(Color::Yellow);
  gradient.addColor(Color::Green);
  gradient.addColor(Color::Cyan);
  gradient.addColor(Color::Blue);
  gradient.addColor(Color::Magenta);
  gradient.addColor(Color::Red);  
 

  viewer << SetMode3D( (*(domain.begin())).styleName(), "Paving" );
  
  for(TDomain::ConstIterator it = domain.begin(), itend=domain.end();
     it!=itend;
     ++it){
   
   unsigned int valDist= resultL1( (*it) );     
   Color c= gradient(valDist);
   
   if(resultL1(*it)<=30 ){
     viewer << CustomColors3D(Color((float)(c.red()), 
				    (float)(c.green()),
				    (float)(c.blue(),205)), 
			      Color((float)(c.red()), 
				    (float)(c.green()),
				    (float)(c.blue()),205));
     viewer << *it ;
   }     
 }
 
  //viewer << ClippingPlane(1,0,0,-60);
 viewer<< Viewer3D::updateDisplay;
 
 return application.exec();
}
Beispiel #10
0
int main( int argc, char** argv )
{

  trace.beginBlock ( "Example simple example of 3DViewer" );
  
  QApplication application(argc,argv);
  Viewer3D<> viewer;
  viewer.setWindowTitle("simpleExample3DViewer");
  viewer.show();  
  
  // Domain cretation from two bounding points.
  Point c( 0, 0, 0 );
  Point p1( -50, -50, -50 );
  Point p2( 50, 50, 50 );
  Domain domain( p1, p2 );
  
  trace.warning() << "Constructing a ring DigitalSet  ... ";
  DigitalSet shape_set( domain );
  for (Domain::ConstIterator it = domain.begin(); it != domain.end(); ++it )
    {
      if ( ((*it - c ).norm() <= 25) && ((*it - c ).norm() >= 18)
     && ( (((*it)[0] <= 3)&& ((*it)[0] >= -3))|| (((*it)[1] <= 3)&& ((*it)[1] >= -3)))){
  shape_set.insertNew( *it );
      }
    }
  trace.warning() << "  [Done]" << std::endl;
  
  trace.beginBlock ( "Thinning" );
  Object18_6 shape( dt18_6,  shape_set );
  int nb_simple=0; 
  DigitalSet::Iterator it, itE;
  do 
    {
      DigitalSet & S = shape.pointSet();
      std::queue<DigitalSet::Iterator> Q;
      it = S.begin(); 
      itE = S.end();
#ifdef WITH_OPENMP
      std::vector<DigitalSet::Iterator> v( S.size() );
      std::vector<uint8_t> b( v.size() );
      for ( size_t i = 0; it != itE; ++it, ++i )
	v[ i ] = it;
#pragma omp parallel for schedule(dynamic)
      for ( size_t i = 0; i < v.size(); ++i )
	b[ i ] = shape.isSimple( *(v[ i ]) );

      for ( size_t i = 0; i < v.size(); ++i )
	if ( b[ i ] ) Q.push( v[ i ] ); 
#else
      for ( ; it != itE; ++it )
	if ( shape.isSimple( *it ) )
	  Q.push( it );
#endif
      nb_simple = 0;
      while ( ! Q.empty() )
	{
	  DigitalSet::Iterator itt = Q.front();
	  Q.pop();
	  if ( shape.isSimple( *itt ) )
	    {
	      S.erase( *itt );
	      ++nb_simple;
	    }
	}
    }
  while ( nb_simple != 0 );
  DigitalSet & S = shape.pointSet();
  trace.endBlock();

  // Display by using two different list to manage OpenGL transparency.

  viewer << SetMode3D( shape_set.className(), "Paving" );
  viewer << CustomColors3D(Color(25,25,255, 255), Color(25,25,255, 255));
  viewer << S ; 

  viewer << SetMode3D( shape_set.className(), "PavingTransp" );
  viewer << CustomColors3D(Color(250, 0,0, 25), Color(250, 0,0, 5));
  viewer << shape_set;

  viewer<< Viewer3D<>::updateDisplay;
   
  
  trace.endBlock();
  return application.exec();

}
int main( int argc, char** argv )
{



 QApplication application(argc,argv);
 Viewer3D<> viewer;
 viewer.setWindowTitle("simpleViewer");
 viewer.show();
 trace.beginBlock ( "Testing class 3DDomain2DView" );

 Z2i::Point p1( 0, 0 );
 Z2i::Point p2( 10, 15 );

 Z3i::Point p13D( 0, 0, 0 );
 Z3i::Point p23D( 10, 15, 0 );

 Z3i::Point p13Dt( 20, 20, 20 );
 Z3i::Point p23Dt( 30, 35, 20 );

 Z3i::Point p13Dtt( 40, 20, 20 );
 Z3i::Point p23Dtt( 50, 35, 20 );

 HyperRectDomain<Z2i::Space> dom ( p1,p2 );
 HyperRectDomain<Z2i::Space> dom2 ( p1,p2 );
 HyperRectDomain<Z2i::Space> dom3 ( p1,p2 );

 HyperRectDomain<Z2i::Space> dom4 ( p1,p2 );
 HyperRectDomain<Z2i::Space> dom5 ( p1,p2 );
 HyperRectDomain<Z2i::Space> dom6 ( p1,p2 );

 HyperRectDomain<Z2i::Space> dom7 ( p1,p2 );
 HyperRectDomain<Z2i::Space> dom8 ( p1,p2 );
 HyperRectDomain<Z2i::Space> dom9 ( p1,p2 );

 viewer << p13D << p23D << p13Dt << p23Dt << p13Dtt << p23Dtt;
 viewer << dom << dom2 << dom3;
 viewer << SetMode3D( dom4.className(), "Grid" );
 viewer << dom4 << dom5 << dom6;
 viewer << SetMode3D( dom4.className(), "Grid" );
 viewer << dom7 << dom8 << dom9;

 viewer << Update2DDomainPosition<Space, KSpace>(0, Viewer3D<Space, KSpace>::xDirection, 0, 0, 0);
 viewer << Update2DDomainPosition<Space, KSpace>(1, Viewer3D<Space, KSpace>::yDirection, 0, 0, 0);
 viewer << Update2DDomainPosition<Space, KSpace>(2, Viewer3D<Space, KSpace>::zDirection, 0, 0, 0);

 viewer << Update2DDomainPosition<Space, KSpace>(3, Viewer3D<Space, KSpace>::xDirection, 0, 0, 0);
 viewer << Update2DDomainPosition<Space, KSpace>(4, Viewer3D<Space, KSpace>::yDirection, 0, 0, 0);
 viewer << Update2DDomainPosition<Space, KSpace>(5, Viewer3D<Space, KSpace>::zDirection, 0, 0, 0);

 viewer << Update2DDomainPosition<Space, KSpace>(6, Viewer3D<Space, KSpace>::xDirection, 0, 0, 0);
 viewer << Update2DDomainPosition<Space, KSpace>(7, Viewer3D<Space, KSpace>::yDirection, 0, 0, 0);
 viewer << Update2DDomainPosition<Space, KSpace>(8, Viewer3D<Space, KSpace>::zDirection, 0, 0, 0);

 viewer << DGtal::Translate2DDomain(3, 20, 20 ,20);
 viewer << DGtal::Translate2DDomain(4, 20, 20 ,20);
 viewer << DGtal::Translate2DDomain(5, 20, 20 ,20);

 viewer << DGtal::Translate2DDomain(6, 40, 20 ,20);
 viewer << DGtal::Translate2DDomain(7, 40, 20 ,20);
 viewer << DGtal::Translate2DDomain(8, 40, 20 ,20);

 viewer <<  Viewer3D<>::updateDisplay;

 bool res = application.exec();
 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
 trace.endBlock();
 return res ? 0 : 1;
}
Beispiel #12
0
int main(int argc, char **argv)
{
  //Reading the image
  try
    {
      typedef ImageContainerBySTLVector< Z2i::Domain, unsigned char> Image;
      Image image = GenericReader<Image>::import("church.pgm");

      //You can access to image domain and values
      trace.info() << image.domain()<<std::endl;
      trace.info() << "Value at (5,5)="<< (int)image( Z2i::Point(5,5) )<<std::endl;

      //Creating the viewer
      // press 'h' for help
      QApplication application(argc,argv);
      Viewer3D<> viewer;
      viewer.setWindowTitle("simpleViewer");
      viewer.show();

      //Display 2 voxels
      viewer << Z3i::Point(2,3,5) ;
      viewer << Z3i::Point(3,2,1) ;

      //Display a triangle
      Z3i::RealPoint p1(1.0,0.0,0.0),
        p2(0.0,1.0,0.0),
        p3(0.0,0.0,1.0);
      viewer.addTriangle(p1,p2,p3);

      //Display a green triangle (with shift)
      Z3i::RealPoint shift(3.0,0.0,0.0);
      viewer<< CustomColors3D(Color(0, 250,0),Color(0, 250,0));
      viewer.addTriangle(p1+shift,
                         p2+shift,
                         p3+shift);

      //A triangle whose color is given by a colormap on scalar function
      // (see colormaps http://libdgtal.org/doc/nightly/moduleIO.html)
      // scalar are 'unsigned char' type here (and we want the 128th color)
      unsigned char maxscalar=255;
      unsigned char minscalar=0;
      HueShadeColorMap<unsigned> huemap(minscalar,maxscalar);
      Z3i::RealPoint shift2(5.0,0.0,0.0);
      viewer<< CustomColors3D(huemap(128),
                              huemap(128));
      viewer.addTriangle(p1+shift2,
                         p2+shift2,
                         p3+shift2);


      //Important: we need to update the display
      viewer  << Viewer3D<>::updateDisplay;

      //infinite loop (ESC to close the viewer)
      bool res = application.exec();
      return res;
    }
  catch(const std::exception& ex)
    {
      trace.info()<< "Error when reading the file "<< ex.what()<< std::endl;
      exit(2);
    }
}
Beispiel #13
0
int main( int argc, char** argv )
{
  // parse command line ----------------------------------------------
  po::options_description general_opt("Allowed options are: ");
  general_opt.add_options()
    ("help,h", "display this message")
    ("input-file,i", po::value<std::string>(), "vol file (.vol) , pgm3d (.p3d or .pgm3d, pgm (with 3 dims)) file or sdp (sequence of discrete points)" )
    ("thresholdMin,m",  po::value<int>()->default_value(0), "threshold min to define binary shape" ) 
    ("thresholdMax,M",  po::value<int>()->default_value(255), "threshold max to define binary shape" )
    ("numMaxVoxel,n",  po::value<int>()->default_value(500000), "set the maximal voxel number to be displayed." )
#ifdef WITH_ITK
    ("dicomMin", po::value<int>()->default_value(-1000), "set minimum density threshold on Hounsfield scale")
    ("dicomMax", po::value<int>()->default_value(3000), "set maximum density threshold on Hounsfield scale")
#endif    
    ("transparency,t",  po::value<uint>()->default_value(255), "transparency") ; 

  bool parseOK=true;
  po::variables_map vm;
  try{
    po::store(po::parse_command_line(argc, argv, general_opt), vm);  
  }catch(const std::exception& ex){
    parseOK=false;
    trace.info()<< "Error checking program options: "<< ex.what()<< endl;
  }
  po::notify(vm);    
  if( !parseOK || vm.count("help")||argc<=1)
    {
      std::cout << "Usage: " << argv[0] << " [input-file]\n"
                << "Display volume file as a voxel set by using QGLviewer"<< endl
                << general_opt << "\n";
      return 0;
    }
  
  if(! vm.count("input-file"))
    {
      trace.error() << " The file name was defined" << endl;      
      return 0;
    }
  string inputFilename = vm["input-file"].as<std::string>();
  int thresholdMin = vm["thresholdMin"].as<int>();
  int thresholdMax = vm["thresholdMax"].as<int>();
  unsigned char transp = vm["transparency"].as<uint>();
  
  bool limitDisplay=false;
  if(vm.count("numMaxVoxel")){
    limitDisplay=true;
  }
  unsigned int numDisplayedMax = vm["numMaxVoxel"].as<int>();
  
  
  QApplication application(argc,argv);
  Viewer3D<> viewer;
  viewer.setWindowTitle("simple Volume Viewer");
  viewer.show();
 
  typedef ImageSelector<Domain, unsigned char>::Type Image;
  string extension = inputFilename.substr(inputFilename.find_last_of(".") + 1);
  if(extension!="vol" && extension != "p3d" && extension != "pgm3D" && extension != "pgm3d" && extension != "sdp" && extension != "pgm" 
 #ifdef WITH_ITK
    && extension !="dcm"
#endif
){
    trace.info() << "File extension not recognized: "<< extension << std::endl;
    return 0;
  }
  
  if(extension=="vol" || extension=="pgm3d" || extension=="pgm3D"
#ifdef WITH_ITK
    || extension =="dcm"
#endif
){
    unsigned int numDisplayed=0;
    
#ifdef WITH_ITK
   int dicomMin = vm["dicomMin"].as<int>();
   int dicomMax = vm["dicomMax"].as<int>();
   typedef DGtal::RescalingFunctor<int ,unsigned char > RescalFCT;
   Image image = extension == "dcm" ? DicomReader< Image,  RescalFCT  >::importDicom( inputFilename, 
											  RescalFCT(dicomMin,
												    dicomMax,
												    0, 255) ) : 
     GenericReader<Image>::import( inputFilename );
#else
   Image image = GenericReader<Image>::import (inputFilename );
#endif

    trace.info() << "Image loaded: "<<image<< std::endl;
    Domain domain = image.domain();
    GradientColorMap<long> gradient( thresholdMin, thresholdMax);
    gradient.addColor(Color::Blue);
    gradient.addColor(Color::Green);
    gradient.addColor(Color::Yellow);
    gradient.addColor(Color::Red);
    for(Domain::ConstIterator it = domain.begin(), itend=domain.end(); it!=itend; ++it){
      unsigned char  val= image( (*it) );     
      if(limitDisplay && numDisplayed > numDisplayedMax)
	break;
      Color c= gradient(val);
      if(val<=thresholdMax && val >=thresholdMin){
	viewer <<  CustomColors3D(Color((float)(c.red()), (float)(c.green()),(float)(c.blue()), transp),
				  Color((float)(c.red()), (float)(c.green()),(float)(c.blue()), transp));     
	viewer << *it;     
	numDisplayed++;
      }     
    }
  }else if(extension=="sdp"){
    vector<Z3i::RealPoint> vectVoxels = PointListReader<Z3i::RealPoint>::getPointsFromFile(inputFilename);
    for(int i=0;i< vectVoxels.size(); i++){
      viewer << vectVoxels.at(i);//Z3i::Point((unsigned int)vectVoxels.at(i)[0],(unsigned int)vectVoxels.at(i)[1],
      //(unsigned int )vectVoxels.at(i)[2]);
    }
  }
  viewer << Viewer3D<>::updateDisplay;
  return application.exec();
}
Beispiel #14
0
int main( int argc, char** argv )
{
  // parse command line ----------------------------------------------
  po::options_description general_opt("Allowed options are: ");
  general_opt.add_options()
    ("help,h", "display this message")
    ("input-file,i", po::value<std::string>(), "volume file" )
    ("thresholdMin,m",  po::value<int>()->default_value(0), "threshold min to define binary shape" ) 
    ("thresholdMax,M",  po::value<int>()->default_value(255), "threshold max to define binary shape" )
    ("transparency,t",  po::value<uint>()->default_value(255), "transparency") ; 
  bool parseOK=true;
  po::variables_map vm;
  try{
    po::store(po::parse_command_line(argc, argv, general_opt), vm);  
  }catch(const std::exception& ex){
    parseOK=false;
    trace.info()<< "Error checking program options: "<< ex.what()<< endl;
  }
  po::notify(vm);    
  if( !parseOK || vm.count("help")||argc<=1)
    {
      std::cout << "Usage: " << argv[0] << " [input-file]\n"
    << "Display volume file as a voxel set by using QGLviewer"
    << general_opt << "\n";
      return 0;
    }
  
  if(! vm.count("input-file"))
    {
      trace.error() << " The file name was defined" << endl;      
      return 0;
    }
  string inputFilename = vm["input-file"].as<std::string>();
  int thresholdMin = vm["thresholdMin"].as<int>();
  int thresholdMax = vm["thresholdMax"].as<int>();
  unsigned char transp = vm["transparency"].as<uint>();
 
  QApplication application(argc,argv);
  Viewer3D viewer;
  viewer.setWindowTitle("simple Volume Viewer");
  viewer.show();
 
  typedef ImageSelector<Domain, unsigned char>::Type Image;
  Image image = VolReader<Image>::importVol( inputFilename );

  trace.info() << "Image loaded: "<<image<< std::endl;

  Domain domain = image.domain();
  GradientColorMap<long> gradient( thresholdMin, thresholdMax);
  gradient.addColor(Color::Blue);
  gradient.addColor(Color::Green);
  gradient.addColor(Color::Yellow);
  gradient.addColor(Color::Red);
  for(Domain::ConstIterator it = domain.begin(), itend=domain.end(); it!=itend; ++it){
    unsigned char  val= image( (*it) );     
   
    Color c= gradient(val);
    if(val<=thresholdMax && val >=thresholdMin){
      viewer <<  CustomColors3D(Color((float)(c.red()), (float)(c.green()),(float)(c.blue()), transp),
        Color((float)(c.red()), (float)(c.green()),(float)(c.blue()), transp));     
      viewer << *it;     
    }     
  }
  viewer << Viewer3D::updateDisplay;
  return application.exec();
}
int main( int argc, char** argv )
{


  QApplication application(argc,argv);
  Viewer3D<> viewer;
  viewer.setWindowTitle("simpleViewer");
  viewer.show();


  typedef ImageSelector < Z3i::Domain, unsigned char>::Type Image3D;
  typedef ImageSelector < Z2i::Domain, unsigned char>::Type Image2D;
  typedef DGtal::ConstImageAdapter<Image3D, Image2D::Domain, DGtal::Projector< Z3i::Space>,
   				   Image3D::Value,  DGtal::DefaultFunctor >  SliceImageAdapter;
  
  typedef DGtal::ConstImageAdapter<Image3D, Z2i::Domain, DGtal::Point2DEmbedderIn3D<DGtal::Z3i::Domain>,
   				   Image3D::Value,  DGtal::DefaultFunctor >  ImageAdapterExtractor;

  DGtal::Projector<DGtal::Z2i::Space>  invFunctor(2);
  // Importing a 3D image 
  std::string filename = examplesPath + "samples/lobster.vol";
  Image3D image = VolReader<Image3D>::importVol( filename ); 
    
  DGtal::Z2i::Domain domain(invFunctor(image.domain().lowerBound()), 
			    invFunctor(image.domain().upperBound()));
  DGtal::DefaultFunctor idV;
    
  trace.beginBlock ( "Example extract2DImagesFrom3D" );
   
  // Extracting 2D slices ... and visualisation on 3DViewer
  unsigned int pos=0;
  for (unsigned int i=0; i<30; i+=5){
    DGtal::Projector<DGtal::Z3i::Space> aSliceFunctor(i); aSliceFunctor.initAddOneDim(2);
    SliceImageAdapter sliceImageZ(image, domain, aSliceFunctor, idV);
    viewer << sliceImageZ; 
    viewer << DGtal::UpdateImagePosition<Z3i::Space, Z3i::KSpace>(pos, Viewer3D<>::zDirection,  i*20, i*20, i*20 );
    pos++;
  }

  // Visu extraction from points
  const int IMAGE_PATCH_WIDTH = 40;
  

  DGtal::Z3i::Point ptCenter(155, 155, 20);
  DGtal::Z2i::Domain domainImage2D (DGtal::Z2i::Point(0,0), 
                                    DGtal::Z2i::Point(IMAGE_PATCH_WIDTH, IMAGE_PATCH_WIDTH)); 
  

  DGtal::Point2DEmbedderIn3D<DGtal::Z3i::Domain >  embedder(image.domain(), ptCenter, 
                                                            DGtal::Z3i::RealPoint(1,-1,1), 
                                                            IMAGE_PATCH_WIDTH);
  
  ImageAdapterExtractor extractedImage(image, domainImage2D, embedder, idV);
  viewer << extractedImage;
  viewer << DGtal::UpdateImage3DEmbedding<Z3i::Space, Z3i::KSpace>(pos, 
                                                                   embedder(Z2i::Point(0,0)),
                                                                   embedder(Z2i::Point(IMAGE_PATCH_WIDTH,0)),
                                                                   embedder(domainImage2D.upperBound()),
                                                                   embedder(Z2i::RealPoint(0, IMAGE_PATCH_WIDTH)));
  
                                   
                                   
  viewer << DGtal::Viewer3D<>::updateDisplay;
    

  application.exec();
  return 0;
}
Beispiel #16
0
int main( int argc, char** argv )
{

    // parse command line ----------------------------------------------
    po::options_description general_opt("Allowed options are: ");
    general_opt.add_options()
    ("help,h", "display this message")
    ("input,i", po::value<std::vector<string> >()->multitoken(), "off files (.off), or OFS file (.ofs) " )
    ("scaleX,x",  po::value<float>()->default_value(1.0), "set the scale value in the X direction (default 1.0)" )
    ("scaleY,y",  po::value<float>()->default_value(1.0), "set the scale value in the Y direction (default 1.0)" )
    ("scaleZ,z",  po:: value<float>()->default_value(1.0), "set the scale value in the Z direction (default 1.0)")
    ("minLineWidth,w",  po:: value<float>()->default_value(1.5), "set the min line width of the mesh faces (default 1.5)")
    ("customColorMesh",po::value<std::vector<unsigned int> >()->multitoken(), "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). " )
    ("customColorSDP",po::value<std::vector<unsigned int> >()->multitoken(), "set the R, G, B, A components of the colors of  the sdp view" )
    ("displayVectorField,f",po::value<std::string>(),  "display a vector field from a simple sdp file (two points per line)" )
    ("vectorFieldIndex",po::value<std::vector<unsigned int> >()->multitoken(), "specify special indices for the two point coordinates (instead usinf the default indices: 0 1, 2, 3, 4, 5)" )
    ("customLineColor",po::value<std::vector<unsigned int> >()->multitoken(), "set the R, G, B components of the colors of the lines displayed from the --displayVectorField option (red by default). " )
    ("displaySDP,s", po::value<std::string>(), "Add the display of a set of discrete points as ball of radius 0.5.")
    ("SDPradius", po::value<double>()->default_value(0.5), "change the ball radius to display a set of discrete points (used with displaySDP option)")
    ("invertNormal,n", "threshold min to define binary shape" )
    ("drawVertex,v", "draw the vertex of the mesh" );

    bool parseOK=true;
    po::variables_map vm;
    try {
        po::store(po::parse_command_line(argc, argv, general_opt), vm);
    } catch(const std::exception& ex) {
        parseOK=false;
        trace.info()<< "Error checking program options: "<< ex.what()<< endl;
    }
    po::notify(vm);
    if( !parseOK || vm.count("help")||argc<=1)
    {
        std::cout << "Usage: " << argv[0] << " [input]\n"
                  << "Display OFF mesh file by using QGLviewer"
                  << general_opt << "\n";
        return 0;
    }

    if(! vm.count("input"))
    {
        trace.error() << " The file name was defined" << endl;
        return 0;
    }



    std::vector<std::string> inputFilenameVect = vm["input"].as<std::vector<std::string > >();
    float sx = vm["scaleX"].as<float>();
    float sy = vm["scaleY"].as<float>();
    float sz = vm["scaleZ"].as<float>();

    unsigned int  meshColorR = 240;
    unsigned int  meshColorG = 240;
    unsigned int  meshColorB = 240;
    unsigned int  meshColorA = 255;

    unsigned int  meshColorRLine = 0;
    unsigned int  meshColorGLine = 0;
    unsigned int  meshColorBLine = 0;
    unsigned int  meshColorALine = 255;


    unsigned int  sdpColorR = 240;
    unsigned int  sdpColorG = 240;
    unsigned int  sdpColorB = 240;
    unsigned int  sdpColorA = 255;


    bool displayVectorField = vm.count("displayVectorField");
    std::vector<unsigned int> vectFieldIndices = {0,1,2,3,4,5};

    if (displayVectorField) {
        if(vm.count("vectorFieldIndex")) {
            vectFieldIndices = vm["vectorFieldIndex"].as<std::vector<unsigned int> >();
            if (vectFieldIndices.size() != 6) {
                trace.warning() << "you should specify indices for each of the 6 fields of the two coordinates." << std::endl;
                vectFieldIndices = {0,1,2,3,4,5};
            }
        }
    }

    float lineWidth = vm["minLineWidth"].as<float>();

    DGtal::Color vFieldLineColor = DGtal::Color::Red;
    if(vm.count("customLineColor")) {
        std::vector<unsigned int > vectCol = vm["customLineColor"].as<std::vector<unsigned int> >();
        if(vectCol.size()!=3 ) {
            trace.error() << "colors specification should contain R,G,B values (using default red)."<< std::endl;
        }
        vFieldLineColor.setRGBi(vectCol[0], vectCol[1], vectCol[2], 255);
    }

    if(vm.count("customColorMesh")) {
        std::vector<unsigned int > vectCol = vm["customColorMesh"].as<std::vector<unsigned int> >();
        if(vectCol.size()!=4 && vectCol.size()!=8 ) {
            trace.error() << "colors specification should contain R,G,B and Alpha values"<< std::endl;
        }
        meshColorR = vectCol[0];
        meshColorG = vectCol[1];
        meshColorB = vectCol[2];
        meshColorA = vectCol[3];
        if(vectCol.size() == 8) {
            meshColorRLine = vectCol[4];
            meshColorGLine = vectCol[5];
            meshColorBLine = vectCol[6];
            meshColorALine = vectCol[7];

        }

    }
    if(vm.count("customColorSDP")) {
        std::vector<unsigned int > vectCol = vm["customColorSDP"].as<std::vector<unsigned int> >();
        if(vectCol.size()!=4) {
            trace.error() << "colors specification should contain R,G,B and Alpha values"<< std::endl;
        }
        sdpColorR = vectCol[0];
        sdpColorG = vectCol[1];
        sdpColorB = vectCol[2];
        sdpColorA = vectCol[3];
    }



    QApplication application(argc,argv);
    Viewer3D<> viewer;
    std::stringstream title;
    title  << "Simple Mesh Viewer: " << inputFilenameVect[0];
    viewer.setWindowTitle(title.str().c_str());
    viewer.show();
    viewer.myGLLineMinWidth = lineWidth;
    viewer.setGLScale(sx, sy, sz);
    bool invertNormal= vm.count("invertNormal");


    double ballRadius = vm["SDPradius"].as<double>();

    trace.info() << "Importing mesh... ";

    std::vector<Mesh<DGtal::Z3i::RealPoint> >  vectMesh;
    for(unsigned int i = 0; i< inputFilenameVect.size(); i++) {
        Mesh<DGtal::Z3i::RealPoint> aMesh(!vm.count("customColorMesh"));
        aMesh << inputFilenameVect[i];
        vectMesh.push_back(aMesh);
    }


    bool import = vectMesh.size()==inputFilenameVect.size();
    if(!import) {
        trace.info() << "File import failed. " << std::endl;
        return 0;
    }

    trace.info() << "[done]. "<< std::endl;
    if(vm.count("displaySDP")) {
        std::string filenameSDP = vm["displaySDP"].as<std::string>();
        vector<Z3i::RealPoint> vectPoints;
        vectPoints = PointListReader<Z3i::RealPoint>::getPointsFromFile(filenameSDP);
        viewer << CustomColors3D(Color(sdpColorR, sdpColorG, sdpColorB, sdpColorA),
                                 Color(sdpColorR, sdpColorG, sdpColorB, sdpColorA));
        for(unsigned int i=0; i< vectPoints.size(); i++) {
            viewer.addBall(vectPoints.at(i), ballRadius);
        }
    }
    if(invertNormal) {
        for(unsigned int i=0; i<vectMesh.size(); i++) {
            vectMesh[i].invertVertexFaceOrder();
        }
    }

    viewer << CustomColors3D(Color(meshColorRLine, meshColorGLine, meshColorBLine, meshColorALine),
                             Color(meshColorR, meshColorG, meshColorB, meshColorA));
    for(unsigned int i=0; i<vectMesh.size(); i++) {
        viewer << vectMesh[i];
    }

    if(vm.count("drawVertex")) {
        for(unsigned int i=0; i<vectMesh.size(); i++) {
            for( Mesh<DGtal::Z3i::RealPoint>::VertexStorage::const_iterator it = vectMesh[i].vertexBegin();
                    it!=vectMesh[i].vertexEnd(); ++it) {
                DGtal::Z3i::Point pt;
                pt[0]=(*it)[0];
                pt[1]=(*it)[1];
                pt[2]=(*it)[2];
                viewer << pt;
            }
        }
    }


    if (displayVectorField) {
        std::vector<unsigned int > vectFieldIndices1 = {vectFieldIndices[0],vectFieldIndices[1], vectFieldIndices[2]};
        std::vector<unsigned int > vectFieldIndices2 = {vectFieldIndices[3],vectFieldIndices[4], vectFieldIndices[5]};

        std::vector<DGtal::Z3i::RealPoint> vectPt1 = PointListReader<DGtal::Z3i::RealPoint>::getPointsFromFile(vm["displayVectorField"].as<std::string>(), vectFieldIndices1);
        std::vector<DGtal::Z3i::RealPoint> vectPt2 = PointListReader<DGtal::Z3i::RealPoint>::getPointsFromFile(vm["displayVectorField"].as<std::string>(), vectFieldIndices2);
        viewer.createNewLineList();
        for (unsigned int i = 0; i < vectPt1.size(); i++) {

            viewer.setLineColor(vFieldLineColor);
            viewer.addLine(vectPt1[i], vectPt2[i]);
        }


    }


    viewer << Viewer3D<>::updateDisplay;
    return application.exec();
}