예제 #1
0
void BccWorld::createTestCurveGeometry()
{
	std::cout<<" gen 1 test curve";
	m_curves->create(1, 9);
	m_curves->counts()[0] = 9;
	
	Vector3F * cvs = m_curves->points();
	cvs[0].set(8.f + RandomFn11(), 1.f + RandomFn11(), 4.1f);
    cvs[1].set(2.f + RandomFn11(), 9.4f + RandomFn11(), 1.11f);
    cvs[2].set(14.f + RandomFn11(), 8.4f + RandomFn11(), -3.13f);
    cvs[3].set(12.f + RandomFn11(), 1.4f + RandomFn11(), 1.14f);
    cvs[4].set(19.f + RandomFn11(), 2.4f + RandomFn11(), 2.16f);
    cvs[5].set(20.f + RandomFn11(), 3.4f + RandomFn11(), 5.17f);
    cvs[6].set(18.f + RandomFn11(), 12.2f + RandomFn11(), 3.18f);
    cvs[7].set(12.f + RandomFn11(), 12.2f + RandomFn11(), 2.19f);
    cvs[8].set(13.f + RandomFn11(), 8.2f + RandomFn11(), -2.18f);
    
    for(unsigned i=0; i<9;i++) {
        cvs[i] -= Vector3F(12.f, 0.f, 0.f);
        cvs[i] *= 3.f;
    }
	
	m_allGeo = new GeometryArray;
	m_allGeo->create(1);
	
	CurveBuilder cb;
	
	unsigned i;
	for(i=0; i< 9; i++)
		cb.addVertex(cvs[i]);
	
	BezierCurve * c = new BezierCurve;
	cb.finishBuild(c);
	m_allGeo->setGeometry(c, 0);
}
예제 #2
0
bool BccWorld::createCurveGeometryFromFile()
{
	if(!readCurveDataFromFile()) return false;
	
	m_allGeo = new GeometryArray;
	m_allGeo->create(m_curves->numCurves());
	
	const unsigned n = m_curves->numCurves();
	m_allGeo = new GeometryArray;
	m_allGeo->create(n);
	
	unsigned * cc = m_curves->counts();
	Vector3F * cvs = m_curves->points();
	
	m_totalCurveLength = 0.f;
	CurveBuilder cb;
	
	unsigned ncv;
	unsigned cvDrift = 0;
	
	unsigned i, j;
	for(i=0; i< n; i++) {
		
		ncv = cc[i];
		
		for(j=0; j < ncv; j++)			
			cb.addVertex(cvs[j + cvDrift]);
		
		BezierCurve * c = new BezierCurve;
		cb.finishBuild(c);
		
		m_totalCurveLength += c->length();
		
		m_allGeo->setGeometry(c, i);
		
		cvDrift += ncv;
	}
    std::cout<<" n curves "<<n
	    <<" total curve length: "<<m_totalCurveLength<<"\n";
    m_numCurves = n;
	return true;
}
예제 #3
0
파일: FitTest.cpp 프로젝트: ahmidou/aphid
void FitTest::createSingleCurve()
{
    m_allGeo->create(1);
    
    BezierCurve * curve = new BezierCurve;
	
	CurveBuilder cb;
	cb.addVertex(Vector3F(-7.5f, 4.f, 5.f));
	cb.addVertex(Vector3F(-7.5f, 6.f, 5.f));
	cb.addVertex(Vector3F(-7.5f, 6.f, 1.f));
	cb.addVertex(Vector3F(-7.5f, 2.f, 1.f));
	cb.addVertex(Vector3F(-7.5f, 1.f, 1.f));
	cb.addVertex(Vector3F(-2.5f, 1.f, 1.f));
	cb.addVertex(Vector3F(.5f, 4.f, 1.f));
	cb.addVertex(Vector3F(-2.f, 10.f, 6.01f));
	cb.addVertex(Vector3F(5.f, 10.f, 5.99f));
	cb.addVertex(Vector3F(5.f, 8.f, 4.01f));
	cb.addVertex(Vector3F(4.f, 8.f, 2.03f));
	cb.addVertex(Vector3F(4.f, 8.5f, 1.01f));
	cb.addVertex(Vector3F(5.1f, 8.95f, 0.f));
	cb.addVertex(Vector3F(3.1f, 8.95f, -3.f));
	
	cb.finishBuild(curve);
	m_allGeo->setGeometry(curve, 0);
}
예제 #4
0
/**
 * \fn int main( int argc , char* argv[]  )
 *
 * \brief A simple program for testing the bc2d library.
 *
 * \param argc The number of command-line arguments.
 * \param argv An array with the command-line arguments.
 *
 * \return An integer number.
 */
int main( int argc , char* argv[] ) {
  //
  // Check command-line arguments.
  //
  
  if ( ( argc != 3 ) && ( argc != 4 ) ) {
    cerr << "Usage: "
         << endl
         << "\t\t channel2d arg1 arg2 [ arg3 ]"
         << endl
         << "\t\t arg1: name of the file describing the polygonal channel"
         << endl
         << "\t\t arg2: name of the output file describing the computed cubic b-spline curve"
         << endl
         << "\t\t arg3: name of an output file to store a CPLEX format definition of the LP solved by this program (OPTIONAL)"
         << endl
         << endl ;
    cerr.flush() ;
    
    return EXIT_FAILURE ;
  }
  
  //
  // Read in the input file.
  //
  
  clock_t start, end ;
  
  cerr << endl
       << "Reading file describing a polygonal channel..."
       << endl ;
  cerr.flush() ;
  
  string fn1( argv[ 1 ] ) ;

  size_t np ;
  size_t nc ;
  bool closed ;
  double* lx ;
  double* ly ;
  double* ux ;
  double* uy ;

  start = clock() ;
  try {
    read_input( fn1 , np , nc , closed , lx , ly , ux , uy ) ;
  }
  catch ( const ExceptionObject& xpt ) {
    treat_exception( xpt ) ;
    exit( EXIT_FAILURE ) ;
  }  
  end = clock() ;
  
  cerr << ( (double) ( end - start ) ) / CLOCKS_PER_SEC
       << " seconds."
       << endl
       << endl ;
  cerr.flush() ;
  
  //
  // Compute a cubic b-spline curve that passes through the channel.
  //
  
  cerr << "Computing a cubic b-spline curve that passes through the channel... "
       << endl ;
  cerr.flush() ;
  
  start = clock() ;
  CurveBuilder* builder = 0 ;
  try {
    builder = new CurveBuilder(
                               np ,
                               nc ,
                               closed ,
                               &lx[ 0 ] ,
                               &ly[ 0 ] ,
                               &ux[ 0 ] ,
                               &uy[ 0 ] 
                              ) ;
  }
  catch ( const ExceptionObject& xpt ) {
    treat_exception( xpt ) ;
    exit( EXIT_FAILURE ) ;
  }
  
  int error ;
  bool res = builder->build( error ) ;
  end = clock() ;
  
  cerr << ( (double) ( end - start ) ) / CLOCKS_PER_SEC
       << " seconds."
       << endl
       << endl ;
  cerr.flush() ;

  if ( res ) {
    //
    // Write the control points of the b-spline to a file.
    //
    cerr << "Writing out the control points of the b-spline to a file..."
	       << endl ;
    cerr.flush() ;

    start = clock() ;
    string fn2( argv[ 2 ] ) ;
    write_solution(
                   fn2 ,
                   *builder
                  ) ;
    end = clock() ;
  
    cerr << ( (double) ( end - start ) ) / CLOCKS_PER_SEC
         << " seconds."
         << endl
         << endl ;
    cerr.flush() ;
  }
  else {
    //
    // Print the error message returned by the LP solver.
    //
    cerr << endl
         << "ATTENTION: "
         << endl
         << builder->get_solver_error_message( error )
         << endl
         << endl ;
  }

  //
  // Generate a description of the linear program in CPLEX format.
  //
  if ( argc == 4 ) {
    cerr << "Writing out a description of the linear program in CPLEX format..."
	       << endl ;
    cerr.flush() ;
  
    start = clock() ;  
    string fn3( argv[ 3 ] ) ;
    write_lp(
             fn3 ,
             *builder
            ) ;
    end = clock() ;
  
    cerr << ( (double) ( end - start ) ) / CLOCKS_PER_SEC
         << " seconds."
         << endl
         << endl ;
    cerr.flush() ;
  }
  
  //
  // Release memory
  //
  
  cerr << "Releasing memory..."
       << endl ;
  cerr.flush() ;
  
  start = clock() ;
  if ( lx != 0 ) delete[ ] lx ;
  if ( ly != 0 ) delete[ ] ly ;
  if ( ux != 0 ) delete[ ] ux ;
  if ( uy != 0 ) delete[ ] uy ;
  if ( builder != 0 ) delete builder ;
  end = clock() ;
  
  cerr << ( (double) ( end - start ) ) / CLOCKS_PER_SEC
  << " seconds."
  << endl
  << endl ;
  cerr.flush() ;
  
  //
  // Done.
  //
  
  cerr << "Finished."
       << endl
       << endl
       << endl ;
  cerr.flush() ;
  
  return EXIT_SUCCESS ;
}