DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testIVViewer.cpp
1 
30 
31 #include <iostream>
32 #include <Qt/qapplication.h>
33 #include <Inventor/nodes/SoCube.h>
34 #include "DGtal/io/viewers/DGtalInventor.h"
35 #include "DGtal/io/viewers/IVViewer.h"
36 #include "DGtal/base/Common.h"
37 #include "DGtal/helpers/StdDefs.h"
38 #include "DGtal/shapes/Shapes.h"
40 
41 using namespace std;
42 using namespace DGtal;
43 using namespace Z3i;
44 
46 // Functions for testing class IVViewer.
48 
52 bool testIVViewerSimpleWdw( int argc, char** argv )
53 {
54  unsigned int nbok = 0;
55  unsigned int nb = 0;
56 
57  trace.beginBlock ( "Testing block ..." );
58  IVViewer ivv( argc, argv );
59  ivv.show();
60  nbok += true ? 1 : 0;
61  nb++;
62  trace.info() << "(" << nbok << "/" << nb << ") "
63  << "true == true" << std::endl;
64  trace.endBlock();
65 
66  return nbok == nb;
67 }
68 
73 bool testIVViewer( int argc, char** argv )
74 {
75  unsigned int nbok = 0;
76  unsigned int nb = 0;
77 
78  trace.beginBlock ( "Testing block ..." );
79  string s = "testIVViewer";
80  for ( int i = 1; i < argc; ++i )
81  s += " " + string( argv[ i ] );
82 
83  IVViewer ivv( argc, argv );
84  //ivv.show();
85  // Setting camera
86  ivv.setCamera( 30.0, 25.0 );
87  // Gives hand to Inventor
88  ivv.setTitle( s.c_str() );
89 
90  DGtalInventor<Space> inventor;
92  inventor.setDiffuseColor( Color( 1.0, 0.0, 0.0 ) );
93  inventor.drawPoint( Point( 1, 0, 0 ) );
94  inventor.setDiffuseColor( Color( 0.0, 1.0, 0.0 ) );
95  inventor.drawPoint( Point( 0, 1, 0 ) );
96  inventor.setDiffuseColor( Color( 0.0, 0.0, 1.0 ) );
97  inventor.drawPoint( Point( 0, 0, 1 ) );
98 
99  Point p1( -4, -4, -4 );
100  Point p2( 17, 17, 17 );
101  Domain domain( p1, p2 );
102  DigitalSet shape_set( domain );
103  Shapes<Domain>::addNorm1Ball( shape_set, Point( 3, 13, 3 ), 7 );
104  Shapes<Domain>::addNorm1Ball( shape_set, Point( 14, 5, 2 ), 12 );
105  inventor.setDiffuseColor( Color( 0.7, 0.7, 0.7 ) );
106  for ( DigitalSet::ConstIterator it = shape_set.begin();
107  it != shape_set.end();
108  ++it )
109  {
110  const Point & p = *it;
111  if ( ( p[ 0 ] < 0 ) || ( p[ 1 ] < 0 ) ||( p[ 2 ] < 0 ) )
112  inventor.setDiffuseColor( Color( 0.7, 0.7, 1.0 ) );
113  else
114  inventor.setDiffuseColor( Color( 1.0, 1.0, 0.7 ) );
115  inventor.drawPoint( *it );
116  }
117  inventor.generate( ivv.root() );
118  // ivv->addChild( node );
119  ivv.show();
120  nbok += true ? 1 : 0;
121  nb++;
122  trace.info() << "(" << nbok << "/" << nb << ") "
123  << "true == true" << std::endl;
124  trace.endBlock();
125 
126  return nbok == nb;
127 }
128 
130 // Standard services - public :
131 
132 int main( int argc, char** argv )
133 {
134  QApplication app( argc, argv );
135  trace.beginBlock ( "Testing class IVViewer" );
136  trace.info() << "Args:";
137  for ( int i = 0; i < argc; ++i )
138  trace.info() << " " << argv[ i ];
139  trace.info() << endl;
140 
141  bool res =
142  // testIVViewerSimpleWdw( argc, argv ) &&
143  testIVViewer( argc, argv );
144  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
145  trace.endBlock();
146  return res ? 0 : 1;
147 }
148 // //