示例#1
0
/**
 * Example of a test. To be completed.
 *
 */
bool testIVViewer( int argc, char** argv )
{
  unsigned int nbok = 0;
  unsigned int nb = 0;
  
  trace.beginBlock ( "Testing block ..." );
  string s = "testIVViewer";
  for ( int i = 1; i < argc; ++i )
    s += " " + string( argv[ i ] );

  IVViewer ivv( argc, argv );
  //ivv.show();
  // Setting camera
  ivv.setCamera( 30.0, 25.0 );
  // Gives hand to Inventor
  ivv.setTitle( s.c_str() );

  DGtalInventor<Space> inventor;
  typedef DGtalInventor<Space>::Color Color;
  inventor.setDiffuseColor( Color( 1.0, 0.0, 0.0 ) );
  inventor.drawPoint( Point( 1, 0, 0 ) );
  inventor.setDiffuseColor( Color( 0.0, 1.0, 0.0 ) );
  inventor.drawPoint( Point( 0, 1, 0 ) );
  inventor.setDiffuseColor( Color( 0.0, 0.0, 1.0 ) );
  inventor.drawPoint( Point( 0, 0, 1 ) );

  Point p1( -4, -4, -4 );
  Point p2( 17, 17, 17 );
  Domain domain( p1, p2 );
  DigitalSet shape_set( domain );
  Shapes<Domain>::addNorm1Ball( shape_set, Point( 3, 13, 3 ), 7 );
  Shapes<Domain>::addNorm1Ball( shape_set, Point( 14, 5, 2 ), 12 );
  inventor.setDiffuseColor( Color( 0.7, 0.7, 0.7 ) );
  for ( DigitalSet::ConstIterator it = shape_set.begin(); 
	it != shape_set.end();
	++it )
    {
      const Point & p = *it;
      if ( ( p[ 0 ] < 0 ) || ( p[ 1 ] < 0 ) ||( p[ 2 ] < 0 ) )
	inventor.setDiffuseColor( Color( 0.7, 0.7, 1.0 ) );
      else
	inventor.setDiffuseColor( Color( 1.0, 1.0, 0.7 ) );
      inventor.drawPoint( *it );
    }
  inventor.generate( ivv.root() );
  // ivv->addChild( node );
  ivv.show();
  nbok += true ? 1 : 0; 
  nb++;
  trace.info() << "(" << nbok << "/" << nb << ") "
	       << "true == true" << std::endl;
  trace.endBlock();
  
  return nbok == nb;
}
示例#2
0
void addAxis( DGtalInventor<Space> & inventor, 
	      const Point & low,
	      const Point & up,
	      Dimension k, 
	      const LibBoard::Color & c1,
	      const LibBoard::Color & c2 )
{
  typedef DGtalInventor<Space>::Color Color;
  // @todo GradientColorMap seems to have a bug
  GradientColorMap<int> cmap_grad( 0, up[ k ] - low[ k ] );
  cmap_grad.clearColors();
  cmap_grad.addColor( c1 );
  cmap_grad.addColor( c2 );
  Point p( low );
  for ( Point::Component x = low[ k ]; x <= up[ k ]; ++x )
    {
      p[ k ] = x;
      LibBoard::Color c( cmap_grad( x - low[ k ] ) );
      inventor.setDiffuseColor( Color( c.red(), c.green(), c.blue() ) );
      inventor.drawPoint( p );
    }
}
示例#3
0
void addBounds( DGtalInventor<Space> & inventor, 
		const Point & low, 
		const Point & up )
{
  typedef DGtalInventor<Space>::Color Color;
  Point p( low );
  for ( Dimension i = 0; i < 8; ++i )
    {
      Color c;
      for ( Dimension j = 0; j < 3; ++j )
	{
	  p[ j ] = ( i & ( 1 << j ) ) ? up[ j ] : low[ j ];
	  c[ j ] = ( i & ( 1 << j ) ) ? 1.0 : 0.1 ;
	}
      inventor.setDiffuseColor( c ); //Color( 0.1, 0.1, 0.1 ) );
      inventor.drawPoint( p );
    }
  // addAxis( inventor, low, up, 0, 
  // 	   LibBoard::Color::Black, LibBoard::Color::Blue );
  // addAxis( inventor, low, up, 1, 
  //  	   LibBoard::Color::Black, LibBoard::Color::Green );
  // addAxis( inventor, low, up, 2, 
  //  	   LibBoard::Color::Black, LibBoard::Color::Red );
}
示例#4
0
int main( int argc, char** argv )
{
  QApplication app( argc, argv );
  trace.beginBlock ( "Testing class IVViewer" );
  IVViewer ivv( argc, argv );

  // Load volumetric image
  typedef ImageSelector<Domain, unsigned char>::Type Image;
  std::string filename = testPath + "samples/cat10.vol";
  Image image = VolReader<Image>::importVol( filename );
  trace.info() << image <<endl;

  // make shape.
  Domain domain( image.lowerBound(), image.upperBound() );
  DigitalSet shape_set( domain );
  for ( Domain::ConstIterator it = domain.begin(), itend = domain.end();
	it != itend;   
	++it )
    {
      if ( image( *it ) != 0 )
	shape_set.insert( *it );
    }

  // find first surfel on the boundary (not nice).
  Point first;
  for ( Domain::ConstIterator it = domain.begin(), itend = domain.end();
	it != itend;   
	++it )
    {
      if ( image( *it ) != 0 )
	{
	  first = *it;
	  break;
	}
    }

  // Builds Khalimsky space.
  typedef KhalimskySpaceND<3> KSpace;
  typedef KSpace::SCell SCell;
  KSpace K3;
  SurfelAdjacency<KSpace::dimension> SAdj( true );
  K3.init( image.lowerBound(), image.upperBound(), true );

  // Tracks the shape boundary.
  SCell intvoxel = K3.sSpel( first );
  SCell surfel = K3.sIncident( intvoxel, 0, false );
  std::set<SCell> bdry;
  Surfaces<KSpace>::trackBoundary( bdry,
				   K3, SAdj, shape_set, surfel );

  trace.info() << "tracking finished, size=" << bdry.size() << endl; 

  // Display surface.
  DGtalInventor<Space> inventor;
  typedef DGtalInventor<Space>::Color Color;
  addBounds( inventor, image.lowerBound(), image.upperBound() );
  for ( std::set<SCell>::const_iterator it = bdry.begin(), itend = bdry.end();
	it != itend;
	++it )
    {
      inventor.setDiffuseColor( Color( 0.7, 0.7, 1.0 ) );
      inventor.drawCell( K3.sKCoords( *it ), 
			 ! K3.sDirect( *it, K3.sOrthDir( *it ) ) );
    }
  // start surfel is red.
  inventor.setDiffuseColor( Color( 1.0, 0.0, 0.0 ) );
  inventor.drawCell( K3.sKCoords( surfel ), 
		     ! K3.sDirect( surfel, K3.sOrthDir( surfel ) ) );
  inventor.generate( ivv.root() );
  // Qt will get the hand.
  ivv.show();

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