int main( int argc, char** argv )
{
  if ( argc < 4 )
    {
      usage( argc, argv );
      return 1;
    }
  std::string inputFilename = argv[ 1 ];
  unsigned int minThreshold = atoi( argv[ 2 ] );
  unsigned int maxThreshold = atoi( argv[ 3 ] );

  //! [volScanBoundary-readVol]
  trace.beginBlock( "Reading vol file into an image." );
  typedef ImageSelector < Domain, int>::Type Image;
  Image image = VolReader<Image>::importVol(inputFilename);
  DigitalSet set3d (image.domain());
  SetFromImage<DigitalSet>::append<Image>(set3d, image, 
                                          minThreshold, maxThreshold);
  trace.endBlock();
  //! [volScanBoundary-readVol]
  
  
  //! [volScanBoundary-KSpace]
  trace.beginBlock( "Construct the Khalimsky space from the image domain." );
  KSpace ks;
  bool space_ok = ks.init( image.domain().lowerBound(), 
                           image.domain().upperBound(), true );
  if (!space_ok)
    {
      trace.error() << "Error in the Khamisky space construction."<<std::endl;
      return 2;
    }
  trace.endBlock();
  //! [volScanBoundary-KSpace]

  //! [volScanBoundary-ExtractingSurface]
  trace.beginBlock( "Extracting boundary by scanning the space. " );
  KSpace::SCellSet boundary;
  Surfaces<KSpace>::sMakeBoundary( boundary, ks, set3d,
                                   image.domain().lowerBound(), 
                                   image.domain().upperBound() );
  trace.endBlock();
  //! [volScanBoundary-ExtractingSurface]

  //! [volScanBoundary-DisplayingSurface]
  trace.beginBlock( "Displaying surface in Viewer3D." );
  QApplication application(argc,argv);
  Viewer3D viewer;
  viewer.show(); 
  viewer << CustomColors3D(Color(250, 0, 0 ), Color( 128, 128, 128 ) );
  unsigned long nbSurfels = 0;
  for ( KSpace::SCellSet::const_iterator it = boundary.begin(),
          it_end = boundary.end(); it != it_end; ++it, ++nbSurfels )
    viewer << *it;
  viewer << Viewer3D::updateDisplay;
  trace.info() << "nb surfels = " << nbSurfels << std::endl;
  trace.endBlock();
  return application.exec();
  //! [volScanBoundary-DisplayingSurface]
}
bool testSphericalViewerInteger(int argc, char **argv)
{
  QApplication application(argc,argv);

  trace.beginBlock ( "Testing Spherical Accumulator Viewer  with Integer numbers..." );

  typedef Z3i::Vector Vector;

  SphericalAccumulator<Vector> accumulator(15);
  trace.info()<< accumulator << std::endl;

  for(unsigned int i=0; i< 10000; i++)
    accumulator.addDirection( Vector (1+(rand()-RAND_MAX/2),
                                      (1+(rand()-RAND_MAX/2)),
                                      (1+(rand()-RAND_MAX/2))));

  Viewer3D<> viewer;
  viewer.show();
  Vector a,b,c,d;
  Display3DFactory<Space,KSpace>::draw(viewer,accumulator, Z3i::RealVector(1.0,1.0,1.0), 3.0);

    trace.info() << "Bin values: ";
  for(SphericalAccumulator<Vector>::ConstIterator it=accumulator.begin(), itend=accumulator.end();
      it != itend;
      ++it)
    trace.info() << *it<<" ";
  trace.info() << std::endl;
  trace.info() << accumulator<<std::endl;

  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 )
{

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

 Point p1( 0, 0, 0 );
 Point p2( 20, 20, 20 );
 Domain domain(p1, p2);
 DigitalSet shape_set( domain );
 
 Shapes<Domain>::addNorm2Ball( shape_set, Point( 10, 10, 10 ), 7 );
 viewer << SetMode3D( shape_set.styleName(), "Both" );
 viewer << shape_set;
 viewer << CustomColors3D(Color(250, 200,0, 100),Color(250, 200,0, 20));
 viewer <<  SetMode3D( p1.styleName(), "Paving" );
 
 //viewer << ClippingPlane(1,0,0,-4.9);
 viewer << ClippingPlane(0,1,0.3,-10); 
 
 
 
 
 viewer << Viewer3D::updateDisplay;
 return application.exec();
}
int main( int argc, char** argv )
{

  std::string inputFilename = examplesPath + "samples/Al.100.vol"; 
  QApplication application(argc,argv);
  Viewer3D viewer;
  viewer.show(); 
  
  typedef ImageSelector < Z3i::Domain, int>::Type Image;
  // Image image = VolReader<Image>::VolReader<Image>::importVol(inputFilename);
  Image image = VolReader<Image>::importVol(inputFilename);
  Z3i::DigitalSet set3d (image.domain());
  SetFromImage<Z3i::DigitalSet>::append<Image>(set3d, image, 0,255);
  Z3i::Object18_6 obj3d (Z3i::dt18_6, set3d);
  Z3i::Object18_6 border = obj3d.border();
  viewer << border;
  viewer << ClippingPlane(0,1,0, -40) << Display3D::updateDisplay;
  //viewer << ClippingPlane(0,-1,0, 70)<< Viewer3D::updateDisplay;
  //viewer << ClippingPlane(1,0.1,0, -50)<< Viewer3D::updateDisplay;
  //viewer << ClippingPlane(1,0.1,0, -50)<< Viewer3D::updateDisplay;
  
  

  
  return application.exec();   
}
int main( int argc, char** argv )
{
  std::string inputFilename = examplesPath + "samples/pointList3d.pl";
  QApplication application(argc,argv);
  Viewer3D<> viewer;
  viewer.show();
  // Importing the 3d set of points  contained with the default index (0, 1, 2);
  vector<Z3i::Point> vectPoints=  PointListReader<Z3i::Point>::getPointsFromFile(inputFilename);
  for(unsigned int i=0; i<vectPoints.size();i++){
    viewer << vectPoints.at(i);
  }

  // Importing the 3d set of points with another index definition  (0, 2, 1);
  vector<unsigned int> vPos;
  vPos.push_back(0);
  vPos.push_back(2);
  vPos.push_back(1);
  vectPoints=  PointListReader<Z3i::Point>::getPointsFromFile(inputFilename, vPos);
  viewer<< CustomColors3D(Color(255,0,0), Color(255,0,0));
  for(unsigned int i=0; i<vectPoints.size();i++){
    viewer << vectPoints.at(i);
  }

  viewer   << Viewer3D<>::updateDisplay;
  return application.exec();
}
int main( int argc, char** argv )
{

  //! [MeshUseInitDisplay]
  QApplication application(argc,argv);
  Viewer3D<> viewer;
  viewer.show();
  //! [MeshUseInitDisplay]


  //! [MeshUseMeshCreation]
  // A mesh is constructed and faces are added from the vertex set.
  //! [MeshUseMeshConstructor]
  Mesh<Point> aMesh(true);
  //! [MeshUseMeshConstructor]

  //! [MeshUseMeshAddingPoints]
  aMesh.addVertex(Point(0,0,0));
  aMesh.addVertex(Point(1,0,0));
  aMesh.addVertex(Point(1,1,0));
  //! [MeshUseMeshAddingPoints]

  aMesh.addVertex(Point(0,0,1));
  aMesh.addVertex(Point(1,0,1));
  aMesh.addVertex(Point(1,1,1));
  aMesh.addVertex(Point(0,1,1));

  aMesh.addVertex(Point(0,1,0));
  aMesh.addVertex(Point(0,2,0));
  aMesh.addVertex(Point(0,3,1));
  aMesh.addVertex(Point(0,2,2));
  aMesh.addVertex(Point(0,1,2));
  aMesh.addVertex(Point(0,0,1));
  //! [MeshUseMeshAddingBasicFaces]
  aMesh.addTriangularFace(0, 1, 2, Color(150,0,150,104));
  aMesh.addQuadFace(6,5,4,3, Color::Blue);
  //! [MeshUseMeshAddingBasicFaces]

  //! [MeshUseMeshAddingPolygonalFaces]
  vector<unsigned int> listIndex;
  listIndex.push_back(7);
  listIndex.push_back(8);
  listIndex.push_back(9);
  listIndex.push_back(10);
  listIndex.push_back(11);
  listIndex.push_back(12);
  aMesh.addFace(listIndex, Color(150,150,0,54));
  //! [MeshUseMeshAddingPolygonalFaces]
  //! [MeshUseMeshCreation]

  //! [MeshUseDisplay]
  viewer.setLineColor(Color(150,0,0,254));
  viewer << aMesh;
  viewer << Viewer3D<>::updateDisplay;
  //! [MeshUseDisplay]
  bool res = application.exec();
  FATAL_ERROR(res);
  return true;
}
Beispiel #7
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 )
{
  trace.beginBlock ( "Testing class MeshFromPointsDisplay" );
  trace.info() << "Args:";
  for ( int i = 0; i < argc; ++i )
    trace.info() << " " << argv[ i ];
  trace.info() << endl;
  //! [MeshFromPointsUseInitDisplay]
  QApplication application(argc,argv);
  Viewer3D viewer;
  viewer.show();     
  //! [MeshFromPointsUseInitDisplay]

  //! [MeshFromPointsUseMeshCreation]
  MeshFromPoints<Point> aMesh(true);
  aMesh.addVertex(Point(0,0,0));
  aMesh.addVertex(Point(1,0,0));
  aMesh.addVertex(Point(1,1,0));

  aMesh.addVertex(Point(0,0,1));
  aMesh.addVertex(Point(1,0,1));
  aMesh.addVertex(Point(1,1,1));
  aMesh.addVertex(Point(0,1,1));

  aMesh.addVertex(Point(0,1,0));
  aMesh.addVertex(Point(0,2,0));
  aMesh.addVertex(Point(0,3,1));
  aMesh.addVertex(Point(0,2,2));
  aMesh.addVertex(Point(0,1,2));
  aMesh.addVertex(Point(0,0,1));
  
  aMesh.addTriangularFace(0, 1, 2, Color(150,0,150,104));
  aMesh.addQuadFace(6,5,4,3, Color::Blue);
  
  vector<unsigned int> listIndex;
  listIndex.push_back(7);
  listIndex.push_back(8);
  listIndex.push_back(9);
  listIndex.push_back(10);
  listIndex.push_back(11);  
  listIndex.push_back(12);  

  aMesh.addFace(listIndex, Color(150,150,0,54));
  //! [MeshFromPointsUseMeshCreation]
  //! [MeshFromPointsUseDisplay]
  viewer.setLineColor(Color(150,0,0,254));
  viewer << aMesh;
  viewer << Viewer3D::updateDisplay;
  bool res = application.exec();
  //! [MeshFromPointsUseDisplay]
  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
  trace.endBlock();
  return res ? 0 : 1;
}
Beispiel #9
0
int main( int argc, char** argv )
{
  std::string inputFilename = examplesPath + "samples/Al.100.vol";
  QApplication application(argc,argv);
  Viewer3D<> viewer;
  viewer.show();
  typedef ImageSelector < Z3i::Domain, int>::Type Image;
  Image image = VolReader<Image>::importVol(inputFilename);
  Z3i::DigitalSet set3d (image.domain());
  SetFromImage<Z3i::DigitalSet>::append<Image>(set3d, image, 0,255);
  viewer << SetMode3D(image.domain().className(), "BoundingBox");
  viewer << set3d << image.domain()  << Viewer3D<>::updateDisplay;
  return application.exec();
}
Beispiel #10
0
int main( int argc, char** argv )
{
  QApplication application(argc,argv);
  typedef DGtal::SpaceND<3, DGtal::int32_t> MySpace;
  typedef MySpace::Point MyPoint;
  typedef HyperRectDomain<MySpace> MyDomain;
  MyPoint p1( 0, 0, 0 );
  MyPoint p2( 5, 5 ,5 );
  MyPoint p3( 2, 3, 4 );
  MyDomain domain( p1, p2 );
  Viewer3D viewer; // for 3D visualization
  viewer.show();
  viewer << domain;  
  viewer << p1 << p2 << p3;
  viewer<< Viewer3D::updateDisplay;
  return application.exec();
}
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 )
{
 QApplication application(argc,argv);
//! [DigiHelixConstr]
 typedef EllipticHelix < Space > MyHelix;
 typedef NaiveParametricCurveDigitizer3D < MyHelix >  DigitizerHelix;
 typedef NaiveParametricCurveDigitizer3D < MyHelix >::DigitalCurve MyDigitalCurve;
 typedef NaiveParametricCurveDigitizer3D < MyHelix >::MetaData MyMetaData;
//! [DigiHelixConstr]
 trace.info() << "exampleParamCurve3dDigitization" << endl;

 Viewer3D<> viewer;

//! [DigiHelixInit]
 MyDigitalCurve digitalCurve;
 MyMetaData metaData;
 MyHelix helix( 15, 10, 1 );
 DigitizerHelix digitize;
 digitize.init ( M_PI / 2., ( MyHelix::getPeriod() * 10. ) + M_PI / 2., 0.0001 );
 digitize.attach ( &helix );
//! [DigiHelixInit]

//! [DigiHelixComp]
 digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ), back_insert_iterator < MyMetaData > ( metaData ) );
//! [DigiHelixComp]

 trace.info() << "Number of points: " << digitalCurve.size () << " number of metadata: " << metaData.size () << endl;

 viewer.show();

//! [DigiHelixMetadata]
 for ( unsigned int i = 0; i < digitalCurve.size ( ); i++ )
 {
  if ( findMainAxis ( helix, metaData.at ( i ).first ) == 0 )
   viewer.setFillColor ( Color ( 255, 0, 0, 128 ) );
  if ( findMainAxis ( helix, metaData.at ( i ).first ) == 1 )
   viewer.setFillColor ( Color ( 0, 255, 0, 128 ) );
  if ( findMainAxis ( helix, metaData.at ( i ).first ) == 2 )
   viewer.setFillColor ( Color ( 0, 0, 255, 128 ) );
  viewer << SetMode3D ( digitalCurve.at ( i ).className ( ), "PavingWired" ) << digitalCurve.at ( i );
 }
//! [DigiHelixMetadata]
 viewer << Viewer3D<>::updateDisplay;

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


  typedef PointVector<3,int> Point;
  typedef std::vector<Point>::iterator Iterator;
  typedef ArithmeticalDSS3d<Iterator,int,4> SegmentComputer;  
  typedef SaturatedSegmentation<SegmentComputer> Decomposition;

  string inputFilename = examplesPath + "samples/sinus.dat"; 
  vector<Point> sequence = PointListReader<Point>::getPointsFromFile(inputFilename); 


  SegmentComputer algo;
  Decomposition theDecomposition(sequence.begin(), sequence.end(), algo);
  
  ///////////////////////////////////
  //display  
  bool flag = true;    
  #ifdef WITH_VISU3D_QGLVIEWER

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

  Point p;
  viewer  << SetMode3D(p.className(), "Grid");

    unsigned int c = 0;
    Decomposition::SegmentComputerIterator i = theDecomposition.begin();
    for ( ; i != theDecomposition.end(); ++i) {
      SegmentComputer currentSegmentComputer(*i);
       viewer << SetMode3D(currentSegmentComputer.className(), "Points"); 
      viewer << currentSegmentComputer;  
       viewer << SetMode3D(currentSegmentComputer.className(), "BoundingBox"); 
      viewer << currentSegmentComputer;  
      //cerr << currentSegmentComputer << endl;
      c++;
    } 
 
  viewer << Viewer3D::updateDisplay;
  flag = application.exec();
   #endif
  return flag;
}
int main( int argc, char** argv )
{
  QApplication application(argc,argv);
  Viewer3D<> viewer;
  viewer.show();
  //! [ImportOFFfile]
  std::string inputFilename = examplesPath + "samples/tref.off";
  // Since the input points are not necessary integers we use the PointD3D from Display3D.
  Mesh<Viewer3D<>::RealPoint> anImportedMesh;
  anImportedMesh << inputFilename;
  //! [ImportOFFfile]
  trace.info()<< "importating done..."<< endl;
  //! [displayOFFfile]
  viewer.setLineColor(DGtal::Color(150,0,0,254));
  viewer << anImportedMesh;
  viewer << Viewer3D<>::updateDisplay;
  //! [displayOFFfile]
  return application.exec();
}
void displayDSS2d( Viewer3D<space, kspace> & viewer,
		   const KSpace & ks, const StandardDSS6Computer & dss3d,
		   const DGtal::Color & color2d )
{
  typedef typename StandardDSS6Computer::ConstIterator ConstIterator3d;
  typedef typename StandardDSS6Computer::ArithmeticalDSSComputer2d ArithmeticalDSSComputer2d;
  typedef typename ArithmeticalDSSComputer2d::ConstIterator ConstIterator2d;
  typedef typename ArithmeticalDSSComputer2d::Point Point2d;
  typedef typename KSpace::Cell Cell;
  typedef typename KSpace::Point Point3d;
  typedef DGtal::PointVector<2,double> PointD2d;
  typedef typename Display3D<>::BallD3D PointD3D;
  Point3d b = ks.lowerBound();
  for ( DGtal::Dimension i = 0; i < 3; ++i )
    {
      const typename ArithmeticalDSSComputer2d::Primitive & dss2d 
	= dss3d.arithmeticalDSS2d( i ).primitive();
      // draw 2D bounding boxes for each arithmetical dss 2D.
      std::vector<PointD2d> pts2d;
      pts2d.push_back( dss2d.project(dss2d.back(), dss2d.Uf()) );
      pts2d.push_back( dss2d.project(dss2d.back(), dss2d.Lf()) );
      pts2d.push_back( dss2d.project(dss2d.front(), dss2d.Lf()) );
      pts2d.push_back( dss2d.project(dss2d.front(), dss2d.Uf()) );
      std::vector<PointD3D> bb;
      PointD3D p3;
      for ( unsigned int j = 0; j < pts2d.size(); ++j )
	{
	  switch (i) {
	  case 0: p3.center[0] = (double) b[ i ]-0.5; p3.center[1] = pts2d[ j ][ 0 ];  p3.center[2] = pts2d[ j ][ 1 ]; break;
	  case 1: p3.center[0] = pts2d[ j ][ 0 ];  p3.center[1] = (double) b[ i ]-0.5; p3.center[2] = pts2d[ j ][ 1 ];     break;
	  case 2: p3.center[0] = pts2d[ j ][ 0 ];  p3.center[1] = pts2d[ j ][ 1 ];     p3.center[2] = (double) b[ i ]-0.5; break;
	  }
	  bb.push_back( p3 );
	}
      for ( unsigned int j = 0; j < pts2d.size(); ++j ){
	viewer.setLineColor(color2d);
	viewer.addLine( DGtal::Z3i::RealPoint(bb[ j ].center[0], bb[ j ].center[1], bb[ j ].center[2]),
                        DGtal::Z3i::RealPoint(bb[ (j+1)%4 ].center[0], bb[ (j+1)%4 ].center[1], bb[ (j+1)%4 ].center[2]),
			MS3D_LINESIZE );
      }
    } // for ( DGtal::Dimension i = 0; i < 3; ++i )
}
///////////////////////////////////////////////////////////////////////////////
// Functions for testing class SphericalAccumulator.
///////////////////////////////////////////////////////////////////////////////
bool testSphericalViewer(int argc, char **argv)
{
  QApplication application(argc,argv);

  trace.beginBlock ( "Testing Spherical Accumulator Viewer..." );

  typedef Z3i::RealVector Vector;

  SphericalAccumulator<Vector> accumulator(15);
  trace.info()<< accumulator << std::endl;

  for(unsigned int i=0; i< 10000; i++)
    accumulator.addDirection( Vector (1+10.0*(rand()-RAND_MAX/2)/(double)RAND_MAX,
              (1+10.0*(rand()-RAND_MAX/2))/(double)RAND_MAX,
              (1+10.0*(rand()-RAND_MAX/2))/(double)RAND_MAX));

  Viewer3D<> viewer;
  Board3D<> board;
  viewer.show();
  Vector a,b,c,d;
  viewer << accumulator;
  
  
  board << accumulator;
  board.saveOBJ("testSpherical.obj");
  

  trace.info() << "Bin values: ";
  for(SphericalAccumulator<Vector>::ConstIterator it=accumulator.begin(), itend=accumulator.end();
      it != itend;
      ++it)
    trace.info() << *it<<" ";
  trace.info() << std::endl;
  trace.info() << accumulator<<std::endl;

  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)
{
  //Loading point set  argv[1]==PTS  argv[2]==SPHERES
  ifstream mypts (argv[1], std::ifstream::in);
  ifstream myspheres (argv[2], std::ifstream::in);

  QApplication app(argc,argv);
  Viewer3D<> viewer;
  double x,y,z,rad;
  viewer.show();
  
  int cpt= 0;
  while (myspheres.good())
  {
    myspheres>> x;
    myspheres >>y;
    myspheres>> z;
    myspheres >> rad;
    viewer.addBall(Z3i::RealPoint(x,y,z), 0.008,5);
    ++cpt;
  }
  myspheres.close();
  trace.info()<< "Nb balls= "<<cpt<<std::endl;
  
  
  viewer << CustomColors3D(Color::Red, Color::Red);
  
  while (mypts.good())
  {
    mypts>> x;
    mypts >>y;
    mypts>> z;
    viewer.addBall(Z3i::RealPoint(x,y,z), 0.008,5);
  }
  mypts.close();


  
  
  return app.exec();
}
Beispiel #18
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 #19
0
int main( int argc, char** argv )
{

 QApplication application(argc,argv);

 Viewer3D viewer;
 viewer.show();

 Point p1( 0, 0, 0 );
 Point p2( 10, 10 , 10 );
 Domain domain( p1, p2 );
 viewer << domain;
 
 DigitalSet shape_set( domain );
 Shapes<Domain>::addNorm1Ball( shape_set, Point( 5, 5, 5 ), 2 );
 Shapes<Domain>::addNorm2Ball( shape_set, Point( 3, 3, 3 ), 2 );
 
 shape_set.erase(Point(3,3,3));
 shape_set.erase(Point(6,6,6));
 viewer << shape_set << Display3D::updateDisplay; 
 
 return application.exec();
}
Beispiel #20
0
int main( int argc, char** argv )
{

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

  
 Point p1( -1, -1, -2 );
 Point p2( 2, 2, 3 );
 Domain domain( p1, p2 );
 Point p3( 1, 1, 1 );
 Point p4( 2, -1, 3 );
 Point p5( -1, 2, 3 );
 Point p6( 0, 0, 0 );
 Point p0( 0, 2, 1 );
 viewer <<  SetMode3D( p1.styleName(), "PavingWired" );
 viewer << p1 << p2 << p3;
  
 
 //viewer <<  SetMode3D( p1.styleName(), "Grid" );
  viewer << CustomColors3D(Color(250, 0,0),Color(250, 0,0));
  viewer << p4 << p5 ;
  viewer <<  SetMode3D( p1.styleName(), "Both" );
  viewer << CustomColors3D(Color(250, 200,0, 100),Color(250, 0,0, 100));
  viewer << p6;
  viewer << CustomColors3D(Color(250, 200,0, 100),Color(250, 200,0, 20));
  viewer << p0;


  viewer << SetMode3D(domain.styleName(), "Paving");
  viewer << domain << Display3D::updateDisplay;   


 return application.exec();
}
void displayDSS3dTangent( Viewer3D<space, kspace> & viewer,
			  const KSpace & ks, const StandardDSS6Computer & dss3d,
			  const DGtal::Color & color3d )
{
  typedef typename StandardDSS6Computer::Point3d Point;
  typedef typename StandardDSS6Computer::PointD3d PointD3d;
  typedef typename Display3D<>::BallD3D PointD3D;
  Point directionZ3;
  PointD3d P1, P2, direction, intercept, thickness;
  dss3d.getParameters( directionZ3, intercept, thickness );
  assign( direction, directionZ3 );
  direction /= direction.norm();
  assign( P1, *dss3d.begin() );
  assign( P2, *(dss3d.end()-1) );
  double t1 = (P1 - intercept).dot( direction );
  double t2 = (P2 - intercept).dot( direction );

  PointD3d Q1 = intercept + t1 * direction;
  PointD3d Q2 = intercept + t2 * direction;
  viewer.setLineColor(color3d);
  viewer.addLine( DGtal::Z3i::RealPoint(Q1[ 0 ]-0.5, Q1[ 1 ]-0.5, Q1[ 2 ]-0.5), 
		  DGtal::Z3i::RealPoint(Q2[ 0 ]-0.5, Q2[ 1 ]-0.5, Q2[ 2 ]-0.5), 
		  MS3D_LINESIZE );
}
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 )
{
  
  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 )
{

  // 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();

}
int main( int argc, char** argv )
{
  if ( argc < 4 )
    {
      usage( argc, argv );
      return 1;
    }
  std::string inputFilename = argv[ 1 ];
  unsigned int minThreshold = atoi( argv[ 2 ] );
  unsigned int maxThreshold = atoi( argv[ 3 ] );
  unsigned int idxP = (argc <= 4) ? 0 : atoi( argv[ 4 ] );

  //! [volDistanceTraversal-readVol]
  trace.beginBlock( "Reading vol file into an image." );
  typedef ImageSelector < Domain, int>::Type Image;
  Image image = VolReader<Image>::importVol(inputFilename);
  DigitalSet set3d (image.domain());
  SetFromImage<DigitalSet>::append<Image>(set3d, image, 
                                          minThreshold, maxThreshold);
  trace.endBlock();
  //! [volDistanceTraversal-readVol]
  
  
  //! [volDistanceTraversal-KSpace]
  trace.beginBlock( "Construct the Khalimsky space from the image domain." );
  KSpace ks;
  bool space_ok = ks.init( image.domain().lowerBound(), 
                           image.domain().upperBound(), true );
  if (!space_ok)
    {
      trace.error() << "Error in the Khamisky space construction."<<std::endl;
      return 2;
    }
  trace.endBlock();
  //! [volDistanceTraversal-KSpace]

  //! [volDistanceTraversal-SurfelAdjacency]
  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
  MySurfelAdjacency surfAdj( true ); // interior in all directions.
  //! [volDistanceTraversal-SurfelAdjacency]

  //! [volDistanceTraversal-SetUpDigitalSurface]
  trace.beginBlock( "Set up digital surface." );
  typedef LightImplicitDigitalSurface<KSpace, DigitalSet > 
    MyDigitalSurfaceContainer;
  typedef DigitalSurface<MyDigitalSurfaceContainer> MyDigitalSurface;
  SCell bel = Surfaces<KSpace>::findABel( ks, set3d, 100000 );
  MyDigitalSurfaceContainer* ptrSurfContainer = 
    new MyDigitalSurfaceContainer( ks, set3d, surfAdj, bel );
  MyDigitalSurface digSurf( ptrSurfContainer ); // acquired
  trace.endBlock();
  // Find first bel.
  MyDigitalSurface::ConstIterator it = digSurf.begin();
  for ( idxP = idxP % digSurf.size(); idxP != 0; --idxP ) ++it;
  bel = *it;
  //! [volDistanceTraversal-SetUpDigitalSurface]

  //! [volDistanceTraversal-ExtractingSurface]
  trace.beginBlock( "Extracting boundary by distance tracking from an initial bel." );
  typedef CanonicSCellEmbedder<KSpace> SCellEmbedder;
  typedef SCellEmbedder::Value RealPoint;
  typedef RealPoint::Coordinate Scalar;
  typedef ExactPredicateLpSeparableMetric<Space,2> Distance;

  typedef std::binder1st< Distance > DistanceToPoint; 
  typedef Composer<SCellEmbedder, DistanceToPoint, Scalar> VertexFunctor;
  typedef DistanceBreadthFirstVisitor< MyDigitalSurface, VertexFunctor, std::set<SCell> > 
    MyDistanceVisitor;
  typedef MyDistanceVisitor::Node MyNode;
  typedef MyDistanceVisitor::Scalar MySize;

  SCellEmbedder embedder;
  Distance distance;
  DistanceToPoint distanceToPoint = std::bind1st( distance, embedder( bel ) );
  VertexFunctor vfunctor( embedder, distanceToPoint );
  MyDistanceVisitor visitor( digSurf, vfunctor, bel );

  unsigned long nbSurfels = 0;
  MyNode node;
  while ( ! visitor.finished() )
    {
      node = visitor.current();
      ++nbSurfels;
      visitor.expand();
    }
  MySize maxDist = node.second;
  trace.endBlock();
  //! [volDistanceTraversal-ExtractingSurface]

  //! [volDistanceTraversal-DisplayingSurface]
  trace.beginBlock( "Displaying surface in Viewer3D." );
  QApplication application(argc,argv);
  Viewer3D<> viewer;
  viewer.show(); 
  HueShadeColorMap<MySize,1> hueShade( 0, maxDist );
  MyDistanceVisitor visitor2( digSurf, vfunctor, bel );
  viewer << CustomColors3D( Color::Black, Color::White )
         << ks.unsigns( bel );
  visitor2.expand();
  std::vector< MyDistanceVisitor::Node > layer;
  while ( ! visitor2.finished() )
    {
      MyNode n = visitor2.current(); 
      Color c = hueShade( n.second );
      viewer << CustomColors3D( Color::Red, c )
             << ks.unsigns( n.first );
      visitor2.expand();
    }
  viewer << Viewer3D<>::updateDisplay;
  trace.info() << "nb surfels = " << nbSurfels << std::endl;
  trace.endBlock();
  return application.exec();
  //! [volDistanceTraversal-DisplayingSurface]
}
Beispiel #26
0
int main( int argc, char** argv )
{
  if ( argc < 5 )
    {
      usage( argc, argv );
      return 1;
    }
  std::string inputFilename = argv[ 1 ];
  unsigned int minThreshold = atoi( argv[ 2 ] );
  unsigned int maxThreshold = atoi( argv[ 3 ] );
  bool intAdjacency = atoi( argv[ 4 ] ) == 0;

  typedef ImageSelector < Domain, int>::Type Image;
      
  //! [viewMarchingCubes-readVol]
  trace.beginBlock( "Reading vol file into an image." );
  Image image = VolReader<Image>::importVol(inputFilename);
  DigitalSet set3d (image.domain());
  SetFromImage<DigitalSet>::append<Image>(set3d, image,
                                          minThreshold, maxThreshold);
  trace.endBlock();
  //! [viewMarchingCubes-readVol]


  //! [viewMarchingCubes-KSpace]
  trace.beginBlock( "Construct the Khalimsky space from the image domain." );
  KSpace ks;
  bool space_ok = ks.init( image.domain().lowerBound(),
                           image.domain().upperBound(), true );
  if (!space_ok)
    {
      trace.error() << "Error in the Khamisky space construction."<<std::endl;
      return 2;
    }
  trace.endBlock();
  //! [viewMarchingCubes-KSpace]

  //! [viewMarchingCubes-SurfelAdjacency]
  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
  MySurfelAdjacency surfAdj( intAdjacency ); // interior in all directions.
  //! [viewMarchingCubes-SurfelAdjacency]

  //! [viewMarchingCubes-ExtractingSurface]
  trace.beginBlock( "Extracting boundary by scanning the space. " );
  typedef KSpace::SurfelSet SurfelSet;
  typedef SetOfSurfels< KSpace, SurfelSet > MySetOfSurfels;
  typedef DigitalSurface< MySetOfSurfels > MyDigitalSurface;
  MySetOfSurfels theSetOfSurfels( ks, surfAdj );
  Surfaces<KSpace>::sMakeBoundary( theSetOfSurfels.surfelSet(),
                                   ks, set3d,
                                   image.domain().lowerBound(),
                                   image.domain().upperBound() );
  MyDigitalSurface digSurf( theSetOfSurfels );
  trace.info() << "Digital surface has " << digSurf.size() << " surfels."
               << std::endl;
  trace.endBlock();
  //! [viewMarchingCubes-ExtractingSurface]

  //! [viewMarchingCubes-makingMesh]
  trace.beginBlock( "Making triangulated surface. " );
  typedef CanonicEmbedder< Space >                                  TrivialEmbedder;
  typedef ImageLinearCellEmbedder< KSpace, Image, TrivialEmbedder > CellEmbedder;
  typedef CellEmbedder::Value                                       RealPoint;
  typedef TriangulatedSurface< RealPoint >                          TriMesh;
  typedef Mesh< RealPoint >                                         ViewMesh;
  typedef std::map< MyDigitalSurface::Vertex, TriMesh::Index >      VertexMap;
  TriMesh         trimesh;
  ViewMesh        viewmesh;
  TrivialEmbedder trivialEmbedder;
  CellEmbedder    cellEmbedder;
  // The +0.5 is to avoid isosurface going exactly through a voxel
  // center, especially for binary volumes.
  cellEmbedder.init( ks, image, trivialEmbedder, 
                     ( (double) minThreshold ) + 0.5 );
  VertexMap vmap; // stores the map Vertex -> Index
  MeshHelpers::digitalSurface2DualTriangulatedSurface
    ( digSurf, cellEmbedder, trimesh, vmap );
  trace.info() << "Triangulated surface is " << trimesh << std::endl;
  MeshHelpers::triangulatedSurface2Mesh( trimesh, viewmesh );
  trace.info() << "Mesh has " << viewmesh.nbVertex()
               << " vertices and " << viewmesh.nbFaces() << " faces." << std::endl;
  trace.endBlock();
  //! [viewMarchingCubes-makingMesh]

  QApplication application(argc,argv);
  Viewer3D<> viewer;
  viewer.show();
  viewer.setLineColor(Color(150,0,0,254));
  viewer << viewmesh;
  viewer << Viewer3D<>::updateDisplay;
  application.exec();
  
}
Beispiel #27
0
int main( int argc, char** argv )
{


  typedef PointVector<3,int> Point;
  typedef std::vector<Point>::iterator Iterator;
  typedef StandardDSS6Computer<Iterator,int,4> SegmentComputer;  
  typedef GreedySegmentation<SegmentComputer> Decomposition;

  string inputFilename = examplesPath + "samples/sinus.dat"; 
  vector<Point> sequence = PointListReader<Point>::getPointsFromFile(inputFilename); 


  SegmentComputer algo;
  Decomposition theDecomposition(sequence.begin(), sequence.end(), algo);
  
  ///////////////////////////////////
  //display  
  bool flag = true;    
  Point p;

#ifdef WITH_VISU3D_QGLVIEWER

  QApplication application(argc,argv);
  Viewer3D<> viewer;
  viewer.show();
  viewer  << SetMode3D(p.className(), "Grid");

#endif
#ifdef WITH_CAIRO
  Board3DTo2D<> boardViewer;
  boardViewer  << SetMode3D(p.className(), "Grid"); 
  boardViewer << CameraPosition(-23.500000, 12.500000, 42.078199)
       << CameraDirection(0.7200000, -0.280000, -0.620000)
       << CameraUpVector(0.1900000, 0.950000, -0.200000);
  boardViewer << CameraZNearFar(21.578200, 105.578199);
#endif



  unsigned int c = 0;
  Decomposition::SegmentComputerIterator i = theDecomposition.begin();
  for ( ; i != theDecomposition.end(); ++i) {
    SegmentComputer currentSegmentComputer(*i);
     #ifdef WITH_VISU3D_QGLVIEWER
       viewer << SetMode3D(currentSegmentComputer.className(), "Points"); 
       viewer << currentSegmentComputer;  
       viewer << SetMode3D(currentSegmentComputer.className(), "BoundingBox"); 
       viewer << currentSegmentComputer;  
    #endif
    #ifdef WITH_CAIRO   
       boardViewer << SetMode3D(currentSegmentComputer.className(), "Points"); 
       boardViewer << currentSegmentComputer;  
       boardViewer << SetMode3D(currentSegmentComputer.className(), "BoundingBox"); 
       boardViewer << currentSegmentComputer;  
    #endif
    c++;
  } 
  
  
  #ifdef WITH_VISU3D_QGLVIEWER
    viewer << Viewer3D<>::updateDisplay;
    flag = application.exec();
  #endif

  #ifdef WITH_CAIRO
    boardViewer.saveCairo("exampleArithDSS3d.pdf", Board3DTo2D<>::CairoPDF, 600*2, 400*2);
  #endif

  return flag;
}
Beispiel #28
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;


}
Beispiel #29
0
int main( int argc, char** argv )
{
  //! [greedy-plane-segmentation-parseCommandLine]
  // 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>()->default_value( examplesPath + "samples/Al.100.vol" ), "the volume file (.vol)" )
    ("threshold,t",  po::value<unsigned int>()->default_value(1), "the value that defines the isosurface in the image (an integer between 0 and 255)." )
    ("width-num,w",  po::value<unsigned int>()->default_value(1), "the numerator of the rational width (a non-null integer)." )
    ("width-den,d",  po::value<unsigned int>()->default_value(1), "the denominator of the rational width (a non-null integer)." );
  
  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]
                << " [-i <fileName.vol>] [-t <threshold>] [-w <num>] [-d <den>]" << std::endl
                << "Segments the surface at given threshold within given volume into digital planes of rational width num/den." << std::endl
                << general_opt << std::endl;
      return 0;
    }
  string inputFilename = vm["input-file"].as<std::string>();
  unsigned int threshold = vm["threshold"].as<unsigned int>();
  unsigned int widthNum = vm["width-num"].as<unsigned int>();
  unsigned int widthDen = vm["width-den"].as<unsigned int>();
  //! [greedy-plane-segmentation-parseCommandLine]

  //! [greedy-plane-segmentation-loadVolume]
  QApplication application(argc,argv);
  typedef ImageSelector < Domain, int>::Type Image;
  Image image = VolReader<Image>::importVol(inputFilename);
  DigitalSet set3d (image.domain());
  SetFromImage<DigitalSet>::append<Image>(set3d, image, threshold,255);
  //! [greedy-plane-segmentation-loadVolume]

  //! [greedy-plane-segmentation-makeSurface]
  trace.beginBlock( "Set up digital surface." );
  // We initializes the cellular grid space used for defining the
  // digital surface.
  KSpace ks;
  bool ok = ks.init( set3d.domain().lowerBound(),
                     set3d.domain().upperBound(), true );
  if ( ! ok ) std::cerr << "[KSpace.init] Failed." << std::endl;
  SurfelAdjacency<KSpace::dimension> surfAdj( true ); // interior in all directions.
  MyDigitalSurfaceContainer* ptrSurfContainer = 
    new MyDigitalSurfaceContainer( ks, set3d, surfAdj );
  MyDigitalSurface digSurf( ptrSurfContainer ); // acquired
  trace.endBlock();
  //! [greedy-plane-segmentation-makeSurface]

  //! [greedy-plane-segmentation-segment]
  trace.beginBlock( "Segment into planes." );
  std::set<Vertex> processedVertices;
  std::vector<SegmentedPlane*> segmentedPlanes;
  std::map<Vertex,SegmentedPlane*> v2plane;
  Point p;
  Dimension axis;
  unsigned int j = 0;
  unsigned int nb = digSurf.size();
  for ( ConstIterator it = digSurf.begin(), itE= digSurf.end(); it != itE; ++it )
    {
      if ( ( (++j) % 50 == 0 ) || ( j == nb ) ) trace.progressBar( j, nb );
      Vertex v = *it;
      if ( processedVertices.find( v ) != processedVertices.end() ) // already in set
        continue; // process to next vertex
      
      SegmentedPlane* ptrSegment = new SegmentedPlane;
      segmentedPlanes.push_back( ptrSegment ); // to delete them afterwards.
      axis = ks.sOrthDir( v );
      ptrSegment->plane.init( axis, 500, widthNum, widthDen );
      // The visitor takes care of all the breadth-first traversal.
      Visitor visitor( digSurf, v );
      while ( ! visitor.finished() )
        {
          Visitor::Node node = visitor.current();
          v = node.first;
          if ( processedVertices.find( v ) == processedVertices.end() )
            { // Vertex is not in processedVertices
              axis = ks.sOrthDir( v );
              p = ks.sCoords( ks.sDirectIncident( v, axis ) );
              bool isExtended = ptrSegment->plane.extend( p );
              if ( isExtended ) 
                { // surfel is in plane.
                  processedVertices.insert( v );
                  v2plane[ v ] = ptrSegment;
                  visitor.expand();
                }
              else // surfel is not in plane and should not be used in the visit.
                visitor.ignore();
            }
          else // surfel is already in some plane.
            visitor.ignore();
        }
      // Assign random color for each plane.
      ptrSegment->color = Color( random() % 256, random() % 256, random() % 256, 255 );
    }
  trace.endBlock();
  //! [greedy-plane-segmentation-segment]

  //! [greedy-plane-segmentation-visualization]
  Viewer3D viewer;
  viewer.show(); 
  for ( std::map<Vertex,SegmentedPlane*>::const_iterator 
          it = v2plane.begin(), itE = v2plane.end();
        it != itE; ++it )
    {
      viewer << CustomColors3D( it->second->color, it->second->color );
      viewer << ks.unsigns( it->first );
    }
  viewer << Display3D::updateDisplay;
  //! [greedy-plane-segmentation-visualization]

  //! [greedy-plane-segmentation-freeMemory]
  for ( std::vector<SegmentedPlane*>::iterator 
          it = segmentedPlanes.begin(), itE = segmentedPlanes.end(); 
        it != itE; ++it )
    delete *it;
  segmentedPlanes.clear();
  v2plane.clear();
  //! [greedy-plane-segmentation-freeMemory]

  return application.exec();
}
Beispiel #30
0
int main( int argc, char** argv )
{
  trace.beginBlock ( "Example ctopo-2-3d" );
  // for 3D display with Viewer3D
  QApplication application(argc,argv);
  
  typedef ImageSelector < Z3i::Domain, int>::Type Image;
  std::string inputFilename = examplesPath + "samples/cat10.vol"; 
  Image image = VolReader<Image>::importVol(inputFilename);
  Z3i::DigitalSet set3d (image.domain());
  SetPredicate<Z3i::DigitalSet> set3dPredicate( set3d );
  SetFromImage<Z3i::DigitalSet>::append<Image>(set3d, image, 0,255);
  Viewer3D viewer;  
  viewer.show(); 
  
  
  // Construct the Khalimsky space from the image domain
  Z3i::KSpace ks;
  bool space_ok = ks.init( image.domain().lowerBound(), image.domain().upperBound(), true );
  
  ASSERT(space_ok);

  std::vector<Z3i::SCell> vectBdrySCell;
  std::vector<Z3i::SCell> vectBdrySCell2;
  std::set<Z3i::SCell> vectBdrySCellALL;
  SurfelAdjacency<3> SAdj( true );
  

  
  //Extract an initial boundary cell
  Z3i::SCell aCell = Surfaces<Z3i::KSpace>::findABel(ks, set3dPredicate);
  
  // Extracting all boundary surfels which are connected to the initial boundary Cell.
  Surfaces<Z3i::KSpace>::trackBoundary( vectBdrySCellALL,
          ks,SAdj, set3dPredicate, aCell );
    
  // Extract the bondary contour associated to the initial surfel in its first direction
  Surfaces<Z3i::KSpace>::track2DBoundary( vectBdrySCell,
             ks, *(ks.sDirs( aCell )), SAdj, 
            set3dPredicate, aCell );
  
  // Extract the bondary contour associated to the initial surfel in its second direction
  Surfaces<Z3i::KSpace>::track2DBoundary( vectBdrySCell2,
             ks, *(++(ks.sDirs( aCell ))), SAdj, 
            set3dPredicate, aCell );  
  
  
  // Displaying all the surfels in transparent mode
  viewer << SetMode3D((*(vectBdrySCellALL.begin())).styleName(), "Transparent");
  for( std::set<Z3i::SCell>::iterator it=vectBdrySCellALL.begin(); 
       it!= vectBdrySCellALL.end(); it++){
    viewer<< *it;
  } 
  
  // Displaying First surfels cut with gradient colors.;
  GradientColorMap<int> cmap_grad( 0, vectBdrySCell2.size() );
  cmap_grad.addColor( Color( 50, 50, 255 ) );
  cmap_grad.addColor( Color( 255, 0, 0 ) );
  cmap_grad.addColor( Color( 255, 255, 10 ) );
  
  // Need to avoid surfel superposition (the surfel size in increased)
  viewer << Viewer3D::shiftSurfelVisu; 
  viewer << SetMode3D((*(vectBdrySCell2.begin())).styleName(), "");
  viewer.setFillColor(Color(180, 200, 25, 255));
  
  int d=0;
  for( std::vector<Z3i::SCell>::iterator it=vectBdrySCell2.begin(); 
       it!= vectBdrySCell2.end(); it++){
    Color col= cmap_grad(d);
    viewer.setFillColor(Color(col.red(),col.green() ,col.blue(), 255));
    viewer<< *it;
    d++;
  }
  
  GradientColorMap<int> cmap_grad2( 0, vectBdrySCell.size() );
  cmap_grad2.addColor( Color( 50, 50, 255 ) );
  cmap_grad2.addColor( Color( 255, 0, 0 ) );
  cmap_grad2.addColor( Color( 255, 255, 10 ) );
  
  d=0;
  for( std::vector<Z3i::SCell>::iterator it=vectBdrySCell.begin(); 
       it!= vectBdrySCell.end(); it++){
     Color col= cmap_grad2(d);
     viewer.setFillColor(Color(col.red(),col.green() ,col.blue(), 255));
     viewer<< *it;
    d++;
  }
  
  // On need once again to avoid superposition.
  viewer << Viewer3D::shiftSurfelVisu; 
  viewer.setFillColor(Color(18, 200, 25, 255));
  viewer << aCell ;
  viewer << Viewer3D::updateDisplay;
    
  return application.exec();
}