コード例 #1
0
int main(int argc, char **argv)
{
  QApplication application(argc,argv);

  DGtal::Viewer3D<> viewer;

  DGtal::Z3i::Point center(0,0,0);
  DGtal::ImplicitRoundedHyperCube<Z3i::Space> myCube( center, 20, 2.8);
  DGtal::Z3i::Domain domain(myCube.getLowerBound(),
          myCube.getUpperBound());

  DGtal::Z3i::DigitalSet mySet(domain);

  DGtal::Shapes<DGtal::Z3i::Domain>::euclideanShaper( mySet, myCube);


  viewer.show();
  // viewer << mySet << DGtal::Display3D::updateDisplay;


  //! [ImageSetDT-DT]
  typedef DGtal::DistanceTransformation<Z3i::Space, DGtal::Z3i::DigitalSet, Z3i::L2Metric> DTL2;
  DTL2 dt(&domain,&mySet,&Z3i::l2Metric );
  //! [ImageSetDT-DT]

  DTL2::Value maxDT = (*std::max_element(dt.constRange().begin(),
                                         dt.constRange().end()));


  GradientColorMap<DTL2::Value> gradient( 0, maxDT);
  gradient.addColor(DGtal::Color::Blue);
  gradient.addColor(DGtal::Color::Green);
  gradient.addColor(DGtal::Color::Yellow);
  gradient.addColor(DGtal::Color::Red);


  for(Z3i::Domain::ConstIterator it = domain.begin(),
  itend = domain.end(); it != itend;
      ++it)
    if (dt(*it) != 0)
      {
  DTL2::Value  val= dt( *it );
  DGtal::Color c= gradient(val);

  viewer <<  DGtal::CustomColors3D(c,c) << *it    ;

      }


  viewer << DGtal::ClippingPlane(1,0,0,0);
  //@todo updateDisplay is in Display3D or Viewer3D (cf doc)?
  viewer << DGtal::Viewer3D<>::updateDisplay;

  return application.exec();


}
コード例 #2
0
/**
 * Example of a test. To be completed.
 *
 */
bool testLocalConvolutionNormalVectorEstimator ( int argc, char**argv )
{
    unsigned int nbok = 0;
    unsigned int nb = 0;

    trace.beginBlock ( "Testing convolution neighborhood ..." );

    QApplication application ( argc,argv );
    DGtal::Viewer3D<> viewer;

    std::string filename = testPath + "samples/cat10.vol";

    typedef ImageSelector < Z3i::Domain, int>::Type Image;
    Image image = VolReader<Image>::importVol ( filename );
    trace.info() <<image<<std::endl;
    DigitalSet set3d ( image.domain() );
    SetFromImage<DigitalSet>::append<Image> ( set3d, image,
            0,256 );

    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 true; //2; (return a bool !!!)
    }
    trace.endBlock();
    typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
    MySurfelAdjacency surfAdj ( true ); // interior in all directions.

    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

    MyDigitalSurface::ConstIterator it = digSurf.begin();


    //Convolution kernel
    deprecated::ConstantConvolutionWeights< MyDigitalSurface::Size > kernel;

    //Estimator definition
    typedef deprecated::LocalConvolutionNormalVectorEstimator<MyDigitalSurface,
                                                  deprecated::ConstantConvolutionWeights< MyDigitalSurface::Size > > MyEstimator;
    MyEstimator myNormalEstimator ( digSurf, kernel );

    myNormalEstimator.init ( 1.0, 5 );

    MyEstimator::Quantity res = myNormalEstimator.eval ( it );
    trace.info() << "Normal vector at begin() : "<< res << std::endl;

    viewer.show();

    DGtal::Color lineColorSave = viewer.getLineColor();
    viewer.setLineColor( DGtal::Color ( 200,20,20 ));
    for ( MyDigitalSurface::ConstIterator itbis = digSurf.begin(),itend=digSurf.end();
            itbis!=itend; ++itbis )
    {
        viewer << ks.unsigns ( *itbis );

        Point center = ks.sCoords ( *itbis );
        MyEstimator::Quantity normal = myNormalEstimator.eval ( itbis );

        viewer.addLine ( center,
                         DGtal::Z3i::RealPoint(center[0]-3*normal[0],
					       center[1]-3*normal[1],
					       center[2]-3*normal[2]) );
    }
    viewer.setLineColor( lineColorSave);
    viewer<< Viewer3D<>::updateDisplay;

    //Convolution kernel
    deprecated::GaussianConvolutionWeights< MyDigitalSurface::Size > Gkernel ( 14.0 );

    //Estimator definition
    typedef deprecated::LocalConvolutionNormalVectorEstimator<MyDigitalSurface,
                                                              deprecated::GaussianConvolutionWeights< MyDigitalSurface::Size > > MyEstimatorGaussian;
    MyEstimatorGaussian myNormalEstimatorG ( digSurf, Gkernel );

    myNormalEstimatorG.init ( 1.0, 15 );

    MyEstimatorGaussian::Quantity res2 = myNormalEstimatorG.eval ( it );
    trace.info() << "Normal vector at begin() : "<< res2 << std::endl;

    viewer<< CustomColors3D ( Color ( 200, 0, 0 ),Color ( 200, 0,0 ) );
    lineColorSave = viewer.getLineColor();
    viewer.setLineColor( DGtal::Color ( 200,20,20 ));
    for ( MyDigitalSurface::ConstIterator itbis = digSurf.begin(),itend=digSurf.end();
            itbis!=itend; ++itbis )
    {
        viewer << ks.unsigns ( *itbis );

        Point center = ks.sCoords ( *itbis );
        MyEstimatorGaussian::Quantity normal = myNormalEstimatorG.eval ( itbis );
        viewer.addLine ( center,
                         DGtal::Z3i::RealPoint(center[0]-3*normal[0],
					       center[1]-3*normal[1],
					       center[2]-3*normal[2]) );
    }
    viewer.setLineColor( lineColorSave);
    viewer<< Viewer3D<>::updateDisplay;


    nbok += true ? 1 : 0;
    nb++;
    trace.info() << "(" << nbok << "/" << nb << ") "
                 << "true == true" << std::endl;
    trace.endBlock();

    return application.exec();
}