예제 #1
0
void QhullLinkedList_test::
t_QhullLinkedList_iterator()
{
    RboxPoints rcube("c");
    Qhull q(rcube,"QR0");  // rotated unit cube
    QhullVertexList vs(q.endVertex(), q.endVertex());
    QhullVertexListIterator i= vs;
    QCOMPARE(vs.count(), 0);
    QVERIFY(!i.hasNext());
    QVERIFY(!i.hasPrevious());
    i.toBack();
    QVERIFY(!i.hasNext());
    QVERIFY(!i.hasPrevious());

    QhullVertexList vs2 = q.vertexList();
    QhullVertexListIterator i2(vs2);
    QCOMPARE(vs2.count(), 8);
    i= vs2;
    QVERIFY(i2.hasNext());
    QVERIFY(!i2.hasPrevious());
    QVERIFY(i.hasNext());
    QVERIFY(!i.hasPrevious());
    i2.toBack();
    i.toFront();
    QVERIFY(!i2.hasNext());
    QVERIFY(i2.hasPrevious());
    QVERIFY(i.hasNext());
    QVERIFY(!i.hasPrevious());

    // i at front, i2 at end/back, 4 neighbors
    QhullVertexList vs3 = q.vertexList(); // same as vs2
    QhullVertex v3(vs3.first());
    QhullVertex v4= vs3.first();
    QCOMPARE(v3, v4);
    QVERIFY(v3==v4);
    QhullVertex v5(v4.next());
    QVERIFY(v4!=v5);
    QhullVertex v6(v5.next());
    QhullVertex v7(v6.next());
    QhullVertex v8(vs3.last());
    QCOMPARE(i2.peekPrevious(), v8);
    i2.previous();
    i2.previous();
    i2.previous();
    i2.previous();
    QCOMPARE(i2.previous(), v7);
    QCOMPARE(i2.previous(), v6);
    QCOMPARE(i2.previous(), v5);
    QCOMPARE(i2.previous(), v4);
    QVERIFY(!i2.hasPrevious());
    QCOMPARE(i.peekNext(), v4);
    // i.peekNext()= 1.0; // compiler error
    QCOMPARE(i.next(), v4);
    QCOMPARE(i.peekNext(), v5);
    QCOMPARE(i.next(), v5);
    QCOMPARE(i.next(), v6);
    QCOMPARE(i.next(), v7);
    i.next();
    i.next();
    i.next();
    QCOMPARE(i.next(), v8);
    QVERIFY(!i.hasNext());
    i.toFront();
    QCOMPARE(i.next(), v4);
    q.checkAndFreeQhullMemory();
}//t_QhullLinkedList_iterator
예제 #2
0
  double CalcTetBadnessGrad (const Point3d & p1, const Point3d & p2,
			     const Point3d & p3, const Point3d & p4, double h,
			     int pi, Vec<3> & grad)
  {
    double vol, l, ll, lll;
    double err;

    const Point3d *pp1, *pp2, *pp3, *pp4;

    pp1 = &p1;
    pp2 = &p2;
    pp3 = &p3;
    pp4 = &p4;
  
    switch (pi)
      {
      case 2:
	{
	  swap (pp1, pp2);
	  swap (pp3, pp4);
	  break;
	}
      case 3:
	{
	  swap (pp1, pp3);
	  swap (pp2, pp4);
	  break;
	}
      case 4:
	{
	  swap (pp1, pp4);
	  swap (pp3, pp2);
	  break;
	}
      }
  

    Vec3d v1 (*pp1, *pp2);
    Vec3d v2 (*pp1, *pp3);
    Vec3d v3 (*pp1, *pp4);

    Vec3d v4 (*pp2, *pp3);
    Vec3d v5 (*pp2, *pp4);
    Vec3d v6 (*pp3, *pp4);

    vol = -Determinant (v1, v2, v3) / 6;  

    Vec3d gradvol;
    Cross (v5, v4, gradvol);
    gradvol *= (-1.0/6.0);


    double ll1 = v1.Length2();
    double ll2 = v2.Length2();
    double ll3 = v3.Length2();
    double ll4 = v4.Length2();
    double ll5 = v5.Length2();
    double ll6 = v6.Length2();

    ll = ll1 + ll2 + ll3 + ll4 + ll5 + ll6;
    l = sqrt (ll);
    lll = l * ll;

    if (vol <= 1e-24 * lll)
      { 
	grad = Vec3d (0, 0, 0);
	return 1e24;
      }



    Vec3d gradll1 (*pp2, *pp1);
    Vec3d gradll2 (*pp3, *pp1);
    Vec3d gradll3 (*pp4, *pp1);
    gradll1 *= 2;
    gradll2 *= 2;
    gradll3 *= 2;

    Vec3d gradll (gradll1);
    gradll += gradll2;
    gradll += gradll3;

    /*
    Vec3d gradll;
    gradll = v1+v2+v3;
    gradll *= -2;
    */

    err = 0.0080187537 * lll / vol; 


    gradll *= (0.0080187537 * 1.5 * l / vol);
    Vec3d graderr(gradll);
    gradvol *= ( -0.0080187537 * lll / (vol * vol) );
    graderr += gradvol;
  
    if (h > 0)
      {
	/*
	Vec3d gradll1 (*pp2, *pp1);
	Vec3d gradll2 (*pp3, *pp1);
	Vec3d gradll3 (*pp4, *pp1);
	gradll1 *= 2;
	gradll2 *= 2;
	gradll3 *= 2;
	*/
	err += ll / (h*h) + 
	  h*h * ( 1 / ll1 + 1 / ll2 + 1 / ll3 + 
		  1 / ll4 + 1 / ll5 + 1 / ll6 ) - 12;

	graderr += (1/(h*h) - h*h/(ll1*ll1)) * gradll1;
	graderr += (1/(h*h) - h*h/(ll2*ll2)) * gradll2;
	graderr += (1/(h*h) - h*h/(ll3*ll3)) * gradll3;
	cout << "?";
      }


    double errpow;
    if (teterrpow == 2)
      {
        errpow = err*err;   
        grad = (2 * err) * graderr;
      }
    else
      {
        errpow = pow (err, teterrpow);
        grad = (teterrpow * errpow / err) * graderr;
      }
    return errpow;
  }
예제 #3
0
파일: CIcosahedron.cpp 프로젝트: rroc/rtdof
void CIcosahedron::init( float s  ){

	this->clearMesh();
	float p = ((1.0 + sqrt(5.0))/2.0)*s;

	TVector3 v0(s,0.0,p);
	this->iVertices.push_back(v0);
	TVector3 v1(-s,0.0,p);
	this->iVertices.push_back(v1);
	TVector3 v2(s,0.0,-p);
	this->iVertices.push_back(v2);
	TVector3 v3(-s,0.0,-p);
	this->iVertices.push_back(v3);
	TVector3 v4(0.0,p,s);
	this->iVertices.push_back(v4);
	TVector3 v5(0,-p,s);
	this->iVertices.push_back(v5);
	TVector3 v6(0,p,-s);
	this->iVertices.push_back(v6);
	TVector3 v7(0.0,-p,-s);
	this->iVertices.push_back(v7);
	TVector3 v8(p,s,0.0);
	this->iVertices.push_back(v8);
	TVector3 v9(-p,s,0.0);
	this->iVertices.push_back(v9);
	TVector3 v10(p,-s,0.0);
	this->iVertices.push_back(v10);
	TVector3 v11(-p,-s,0.0);
	this->iVertices.push_back(v11);


	TTriangle t0(0,4,1);
	this->iTriangles.push_back(t0);

	TTriangle t1(0,1,5);
	this->iTriangles.push_back(t1);

	TTriangle t2(0,5,10);
	this->iTriangles.push_back(t2);

	TTriangle t3(0,10,8);
	this->iTriangles.push_back(t3);

	TTriangle t4(0,8,4);
	this->iTriangles.push_back(t4);

	TTriangle t5(4,8,6);
	this->iTriangles.push_back(t5);

	TTriangle t6(4,6,9);
	this->iTriangles.push_back(t6);

	TTriangle t7(4,9,1);
	this->iTriangles.push_back(t7);

	TTriangle t8(1,9,11);
	this->iTriangles.push_back(t8);

	TTriangle t9(1,11,5);
	this->iTriangles.push_back(t9);

	TTriangle t10(2,7,3);
	this->iTriangles.push_back(t10);

	TTriangle t11(2,3,6);
	this->iTriangles.push_back(t11);

	TTriangle t12(2,6,8);
	this->iTriangles.push_back(t12);

	TTriangle t13(2,8,10);
	this->iTriangles.push_back(t13);

	TTriangle t14(2,10,7);
	this->iTriangles.push_back(t14);

	TTriangle t15(7,10,5);
	this->iTriangles.push_back(t15);

	TTriangle t16(7,5,11);
	this->iTriangles.push_back(t16);

	TTriangle t17(7,11,3);
	this->iTriangles.push_back(t17);

	TTriangle t18(3,11,9);
	this->iTriangles.push_back(t18);

	TTriangle t19(3,9,6);
	this->iTriangles.push_back(t19);
	}
예제 #4
0
void VectorTest::test_constructor(void)
{
   message += "test_constructor\n";

   std::string file_name = "../data/vector.dat";

   // Default 

   Vector<bool> v1;

   assert_true(v1.size() == 0, LOG);   

   // Size

   Vector<bool> v2(1);

   assert_true(v2.size() == 1, LOG);

   // Size initialization

   Vector<bool> v3(1, false);

   assert_true(v3.size() == 1, LOG);
   assert_true(v3[0] == false, LOG);

   // File

   Vector<int> v4(3, 0);
   v4.save(file_name);

   Vector<int> w4(file_name);
   
   assert_true(w4.size() == 3, LOG);
   assert_true(w4 == 0, LOG);

   // Sequential

   Vector<int> v6(10, 5, 50);

   assert_true(v6.size() == 9, LOG);
   assert_true(v6[0] == 10, LOG);
   assert_true(v6[8] == 50, LOG);

   Vector<double> v7(3.0, 0.2, 3.8);

   assert_true(v7.size() == 5, LOG);
   assert_true(v7[0] == 3.0, LOG);
   assert_true(v7[4] == 3.8, LOG);

   Vector<int> v8(9, -1, 1);

   assert_true(v8.size() == 9, LOG);
   assert_true(v8[0] == 9, LOG);
   assert_true(v8[8] == 1, LOG);

   // Copy

   Vector<std::string> v5(1, "hello");

   Vector<std::string> w5(v5);

   assert_true(w5.size() == 1, LOG);
   assert_true(w5[0] == "hello", LOG);

}
   void QuatGenMetricTest::testGenTimingSetRot()
   {
      double bokd = 1;
      float bokf = 1;
      gmtl::Quat<double> q1;
      const long iters(25000);
      CPPUNIT_METRIC_START_TIMING();

      for (long iter = 0; iter < iters; ++iter)
      {
         gmtl::set( q1, gmtl::makeNormal( gmtl::AxisAngled( bokd, bokd, bokd, bokd ) ) );
         bokd += q1[2];
      }
      CPPUNIT_METRIC_STOP_TIMING();
      CPPUNIT_ASSERT_METRIC_TIMING_LE( "QuatGenTest/setRot(quatd,axisangled)", iters, 0.075f, 0.1f);  // warn at 7.5%, error at 10%

      gmtl::Quat<float> q2; bokf = 1.0f;
      CPPUNIT_METRIC_START_TIMING();
      for (long iter = 0; iter < iters; ++iter)
      {
         gmtl::set( q2, gmtl::makeNormal( gmtl::AxisAnglef( bokf, bokf, bokf, bokf ) ) );
         bokf -= q2[3];
      }
      CPPUNIT_METRIC_STOP_TIMING();
      CPPUNIT_ASSERT_METRIC_TIMING_LE( "QuatGenTest/setRot(quatf,axisanglef)", iters, 0.075f, 0.1f);  // warn at 7.5%, error at 10%


      gmtl::Quat<double> q3; bokd = 1.0f;
      CPPUNIT_METRIC_START_TIMING();
      for (long iter = 0; iter < iters; ++iter)
      {
         gmtl::set( q3, gmtl::makeNormal( gmtl::AxisAngled( bokd, gmtl::Vec<double, 3>( bokd, bokd, bokd ) ) ) );
         bokd *= q3[1] + 1.2;
      }
      CPPUNIT_METRIC_STOP_TIMING();
      CPPUNIT_ASSERT_METRIC_TIMING_LE( "QuatGenTest/setRot(quatd,axisangled(r,vec))", iters, 0.075f, 0.1f);  // warn at 7.5%, error at 10%

      gmtl::Quat<float> q4; bokf = 1.0f;
      CPPUNIT_METRIC_START_TIMING();
      for (long iter = 0; iter < iters; ++iter)
      {
         gmtl::set( q4, gmtl::makeNormal( gmtl::AxisAnglef( bokf, gmtl::Vec<float, 3>( bokf, bokf, bokf ) ) ) );
         bokf += q4[1] + 1.2f;
      }
      CPPUNIT_METRIC_STOP_TIMING();
      CPPUNIT_ASSERT_METRIC_TIMING_LE( "QuatGenTest/setRot(quatf,axisanglef(r,vec))", iters, 0.075f, 0.1f);  // warn at 7.5%, error at 10%


      gmtl::Quat<double> q5;
      gmtl::Vec<double, 3> v4(1,2,3), v5(1,2,3);
      CPPUNIT_METRIC_START_TIMING();
      for (long iter = 0; iter < iters; ++iter)
      {
         gmtl::setRot( q5, gmtl::makeNormal( v4 ), gmtl::makeNormal( v5 ) );
         v4[2] += q5[1] + 1.2;
         v5[0] -= q5[2] + 1.2;
      }
      CPPUNIT_METRIC_STOP_TIMING();
      CPPUNIT_ASSERT_METRIC_TIMING_LE( "QuatGenTest/setRot(quatd,vec3d,vec3d)", iters, 0.075f, 0.1f);  // warn at 7.5%, error at 10%

      gmtl::Quat<float> q6;
      gmtl::Vec<float, 3> v6(1,2,3), v7(1,2,3);
      CPPUNIT_METRIC_START_TIMING();
      for (long iter = 0; iter < iters; ++iter)
      {
         gmtl::setRot( q6, gmtl::makeNormal( v6 ), gmtl::makeNormal( v7 ) );
         v6[2] += q6[1] + 1.2f;
         v7[0] -= q6[2] + 1.2f;
      }
      CPPUNIT_METRIC_STOP_TIMING();
      CPPUNIT_ASSERT_METRIC_TIMING_LE( "QuatGenTest/setRot(quatf,vec3f,vec3f)", iters, 0.075f, 0.1f);  // warn at 7.5%, error at 10%

      // force intelligent compilers to do all the iterations (ie. to not optimize them out),
      // by using the variables computed...
      CPPUNIT_ASSERT( bokf != 0.998f );
      CPPUNIT_ASSERT( bokd != 0.0998 );
      CPPUNIT_ASSERT( q1[0] != 10000.0f );
      CPPUNIT_ASSERT( q2[1] != 10000.0f );
      CPPUNIT_ASSERT( q3[2] != 10000.0f );
      CPPUNIT_ASSERT( q4[3] != 10000.0f );
      CPPUNIT_ASSERT( q5[0] != 10000.0f );
      CPPUNIT_ASSERT( q6[1] != 10000.0f );
   }
예제 #6
0
//----------------------------------------------------------------------------
void BspNodes::CreateScene ()
{
	// Create the scene graph.
	//
	// 1. The rectangles represent the BSP planes of the BSP tree.  They
	//    share a VertexColor3Effect.  You can see a plane from either side
	//    (backface culling disabled).  The planes do not interfere with view
	//    of the solid objects (wirestate enabled).
	//
	// 2. The sphere, tetrahedron, and cube share a TextureEffect.  These
	//    objects are convex.  The backfacing triangles are discarded
	//    (backface culling enabled).  The front facing triangles are drawn
	//    correctly by convexity, so depthbuffer reads are disabled and
	//    depthbuffer writes are enabled.  The BSP-based sorting of objects
	//    guarantees that front faces of convex objects in the foreground
	//    are drawn after the front faces of convex objects in the background,
	//    which allows us to set the depthbuffer state as we have.  That is,
	//    BSPNode sorts from back to front.
	//
	// 3. The torus has backface culling enabled and depth buffering enabled.
	//    This is necessary, because the torus is not convex.
	//
	// 4. Generally, if all objects are opaque, then you want to draw from
	//    front to back with depth buffering fully enabled.  You need to
	//    reverse-order the elements of the visible set before drawing.  If
	//    any of the objects are semitransparent, then drawing back to front
	//    is the correct order to handle transparency.  However, you do not
	//    get the benefit of early z-rejection for opaque objects.  A better
	//    BSP sorter needs to be built to produce a visible set with opaque
	//    objects listed first (front-to-back order) and semitransparent
	//    objects listed last (back-to-front order).
	//
	// scene
	//     ground
	//     bsp0
	//         bsp1
	//             bsp3
	//                 torus
	//                 rectangle3
	//                 sphere
	//             rectangle1
	//             tetrahedron
	//         rectangle0
	//         bsp2
	//             cube
	//             rectangle2
	//             octahedron

	mScene = new0 Node();

	// Create the ground.  It covers a square with vertices (1,1,0), (1,-1,0),
	// (-1,1,0), and (-1,-1,0).  Multiply the texture coordinates by a factor
	// to enhance the wrap-around.
	VertexFormat* vformat = VertexFormat::Create(2,
	                        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
	                        VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0);

	StandardMesh sm(vformat);
	VertexBufferAccessor vba;

	TriMesh* ground = sm.Rectangle(2, 2, 16.0f, 16.0f);
	vba.ApplyTo(ground);
	for (int i = 0; i < vba.GetNumVertices(); ++i)
	{
		Float2& tcoord = vba.TCoord<Float2>(0, i);
		tcoord[0] *= 128.0f;
		tcoord[1] *= 128.0f;
	}

	std::string path = Environment::GetPathR("Horizontal.wmtf");
	Texture2D* texture = Texture2D::LoadWMTF(path);
	ground->SetEffectInstance(Texture2DEffect::CreateUniqueInstance(texture,
	                          Shader::SF_LINEAR_LINEAR, Shader::SC_REPEAT, Shader::SC_REPEAT));
	mScene->AttachChild(ground);

	// Partition the region above the ground into 5 convex pieces.  Each plane
	// is perpendicular to the ground (not required generally).
	VertexColor3Effect* vceffect = new0 VertexColor3Effect();
	vceffect->GetCullState(0, 0)->Enabled = false;
	vceffect->GetWireState(0, 0)->Enabled = true;

	Vector2f v0(-1.0f, 1.0f);
	Vector2f v1(1.0f, -1.0f);
	Vector2f v2(-0.25f, 0.25f);
	Vector2f v3(-1.0f, -1.0f);
	Vector2f v4(0.0f, 0.0f);
	Vector2f v5(1.0f, 0.5f);
	Vector2f v6(-0.75f, -7.0f/12.0f);
	Vector2f v7(-0.75f, 0.75f);
	Vector2f v8(1.0f, 1.0f);

	BspNode* bsp0 = CreateNode(v0, v1, vceffect, Float3(1.0f, 0.0f, 0.0f));
	BspNode* bsp1 = CreateNode(v2, v3, vceffect, Float3(0.0f, 0.5f, 0.0f));
	BspNode* bsp2 = CreateNode(v4, v5, vceffect, Float3(0.0f, 0.0f, 1.0f));
	BspNode* bsp3 = CreateNode(v6, v7, vceffect, Float3(0.0f, 0.0f, 0.0f));

	bsp0->AttachPositiveChild(bsp1);
	bsp0->AttachNegativeChild(bsp2);
	bsp1->AttachPositiveChild(bsp3);

	// Attach an object in each convex region.
	float height = 0.1f;
	Vector2f center;
	TriMesh* mesh;

	// The texture effect for the convex objects.
	Texture2DEffect* cvxeffect =
	    new0 Texture2DEffect(Shader::SF_LINEAR_LINEAR);
	cvxeffect->GetDepthState(0, 0)->Enabled = false;
	cvxeffect->GetDepthState(0, 0)->Writable = true;

	// The texture effect for the torus.
	Texture2DEffect* toreffect =
	    new0 Texture2DEffect(Shader::SF_LINEAR_LINEAR);

	// The texture image shared by the objects.
	path = Environment::GetPathR("Flower.wmtf");
	texture = Texture2D::LoadWMTF(path);

	// Region 0: Create a torus mesh.
	mesh = sm.Torus(16, 16, 1.0f, 0.25f);
	mesh->SetEffectInstance(toreffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v2 + v6 + v7)/3.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp3->AttachPositiveChild(mesh);

	// Region 1: Create a sphere mesh.
	mesh = sm.Sphere(32, 16, 1.0f);
	mesh->SetEffectInstance(cvxeffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v0 + v3 + v6 + v7)/4.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp3->AttachNegativeChild(mesh);

	// Region 2: Create a tetrahedron.
	mesh = sm.Tetrahedron();
	mesh->SetEffectInstance(cvxeffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v1 + v2 + v3)/3.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp1->AttachNegativeChild(mesh);

	// Region 3: Create a hexahedron (cube).
	mesh = sm.Hexahedron();
	mesh->SetEffectInstance(cvxeffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v1 + v4 + v5)/3.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp2->AttachPositiveChild(mesh);

	// Region 4: Create an octahedron.
	mesh = sm.Octahedron();
	mesh->SetEffectInstance(cvxeffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v0 + v4 + v5 + v8)/4.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp2->AttachNegativeChild(mesh);

	mScene->AttachChild(bsp0);
}
/* Call functions through pointers and and check against expected results.  */
void
test (void)
{

  CHECK_VOID_RESULT (v0 (), 1.0);
  CHECK_VOID_RESULT (v1 (1.0), 2.0);
  CHECK_VOID_RESULT (v5 (5.0, 6.0), 12.0);
  CHECK_VOID_RESULT (v9 (9.0, 10.0), 20.0);
  CHECK_VOID_RESULT (v2 (2.0), 3.0);
  CHECK_VOID_RESULT (v6 (6.0, 7.0), 14.0);
  CHECK_VOID_RESULT (v10 (10.0, 11.0), 22.0);

  CHECK_RESULT (f0 (), 1.0);
  CHECK_RESULT (f1 (1.0), 2.0);
  CHECK_RESULT (f5 (5.0, 6.0), 12.0);
  CHECK_RESULT (f9 (9.0, 10.0), 20.0);
  CHECK_RESULT (f2 (2.0), 3.0);
  CHECK_RESULT (f6 (6.0, 7.0), 14.0);
  CHECK_RESULT (f10 (10.0, 11.0), 22.0);

  CHECK_RESULT (d0 (), 1.0);
  CHECK_RESULT (d1 (1.0), 2.0);
  CHECK_RESULT (d5 (5.0, 6.0), 12.0);
  CHECK_RESULT (d9 (9.0, 10.0), 20.0);
  CHECK_RESULT (d2 (2.0), 3.0);
  CHECK_RESULT (d6 (6.0, 7.0), 14.0);
  CHECK_RESULT (d10 (10.0, 11.0), 22.0);

  CHECK_RESULT (cf0 (), 1.0 + 0.0i);
  CHECK_RESULT (cf1 (1.0), 2.0 + 1.0i);
  CHECK_RESULT (cf5 (5.0, 6.0), 12.0 + 5.0i);
  CHECK_RESULT (cf9 (9.0, 10.0), 20.0 + 9.0i);
  CHECK_RESULT (cf2 (2.0), 3.0 + 2.0i);
  CHECK_RESULT (cf6 (6.0, 7.0), 14.0 + 6.0i);
  CHECK_RESULT (cf10 (10.0, 11.0), 22.0 + 10.0i);

  CHECK_RESULT (cd0 (), 1.0 + 0.0i);
  CHECK_RESULT (cd1 (1.0), 2.0 + 1.0i);
  CHECK_RESULT (cd5 (5.0, 6.0), 12.0 + 5.0i);
  CHECK_RESULT (cd9 (9.0, 10.0), 20.0 + 9.0i);
  CHECK_RESULT (cd2 (2.0), 3.0 + 2.0i);
  CHECK_RESULT (cd6 (6.0, 7.0), 14.0 + 6.0i);
  CHECK_RESULT (cd10 (10.0, 11.0), 22.0 + 10.0i);

  CHECK_VOID_RESULT ((*pv0) (), 1.0);
  CHECK_VOID_RESULT ((*pv1) (1.0), 2.0);
  CHECK_VOID_RESULT ((*pv5) (5.0, 6.0), 12.0);
  CHECK_VOID_RESULT ((*pv9) (9.0, 10.0), 20.0);
  CHECK_VOID_RESULT ((*pv2) (2.0), 3.0);
  CHECK_VOID_RESULT ((*pv6) (6.0, 7.0), 14.0);
  CHECK_VOID_RESULT ((*pv10) (10.0, 11.0), 22.0);

  CHECK_RESULT ((*pf0) (), 1.0);
  CHECK_RESULT ((*pf1) (1.0), 2.0);
  CHECK_RESULT ((*pf5) (5.0, 6.0), 12.0);
  CHECK_RESULT ((*pf9) (9.0, 10.0), 20.0);
  CHECK_RESULT ((*pf2) (2.0), 3.0);
  CHECK_RESULT ((*pf6) (6.0, 7.0), 14.0);
  CHECK_RESULT ((*pf10) (10.0, 11.0), 22.0);

  CHECK_RESULT ((*pd0) (), 1.0);
  CHECK_RESULT ((*pd1) (1.0), 2.0);
  CHECK_RESULT ((*pd5) (5.0, 6.0), 12.0);
  CHECK_RESULT ((*pd9) (9.0, 10.0), 20.0);
  CHECK_RESULT ((*pd2) (2.0), 3.0);
  CHECK_RESULT ((*pd6) (6.0, 7.0), 14.0);
  CHECK_RESULT ((*pd10) (10.0, 11.0), 22.0);

  CHECK_RESULT ((*pcf0) (), 1.0 + 0.0i);
  CHECK_RESULT ((*pcf1) (1.0), 2.0 + 1.0i);
  CHECK_RESULT ((*pcf5) (5.0, 6.0), 12.0 + 5.0i);
  CHECK_RESULT ((*pcf9) (9.0, 10.0), 20.0 + 9.0i);
  CHECK_RESULT ((*pcf2) (2.0), 3.0 + 2.0i);
  CHECK_RESULT ((*pcf6) (6.0, 7.0), 14.0 + 6.0i);
  CHECK_RESULT ((*pcf10) (10.0, 11.0), 22.0 + 10.0i);

  CHECK_RESULT ((*pcd0) (), 1.0 + 0.0i);
  CHECK_RESULT ((*pcd1) (1.0), 2.0 + 1.0i);
  CHECK_RESULT ((*pcd5) (5.0, 6.0), 12.0 + 5.0i);
  CHECK_RESULT ((*pcd9) (9.0, 10.0), 20.0 + 9.0i);
  CHECK_RESULT ((*pcd2) (2.0), 3.0 + 2.0i);
  CHECK_RESULT ((*pcd6) (6.0, 7.0), 14.0 + 6.0i);
  CHECK_RESULT ((*pcd10) (10.0, 11.0), 22.0 + 10.0i);
}
예제 #8
0
osg::Drawable *ReverseTileNode::createReverseTile(void) const {
    // Get the tile
    ReverseTile* tile = static_cast<ReverseTile*>(_lego);

    // Get tile color
    QColor color = tile->getColor();

    // Get integer sizes
    int width = tile->getWidth();
    int length = tile->getLength();
    int height = 3;

    // Get real position, according to tile size
    double mw = (-width)*Lego::length_unit/2;
    double pw = (width)*Lego::length_unit/2;
    double mwp = (-width+2)*Lego::length_unit/2;
    double ml = (-length)*Lego::length_unit/2;
    double pl = (length)*Lego::length_unit/2;
    double mh = (-height)*Lego::height_unit/2;
    double ph = (height)*Lego::height_unit/2;
    double phm = (height-1)*Lego::height_unit/2;

    // Create 14 vertices
    osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
    osg::Vec3 v0(mw, ml, mh);
    osg::Vec3 v1(mw, pl, mh);
    osg::Vec3 v2(mwp, pl, mh);
    osg::Vec3 v3(mwp, ml, mh);
    osg::Vec3 v4(pw, ml, phm);
    osg::Vec3 v5(pw, pl, phm);
    osg::Vec3 v6(pw, pl, ph);
    osg::Vec3 v7(pw, ml, ph);
    osg::Vec3 v8(mw, ml, ph);
    osg::Vec3 v9(mw, pl, ph);
    osg::Vec3 v10(mwp, ml, phm);
    osg::Vec3 v11(mwp, ml, ph);
    osg::Vec3 v12(mwp, pl, ph);
    osg::Vec3 v13(mwp, pl, phm);

    // Create 10 faces, 8 faces are quads splitted into two triangles
    // NB: Down face is transparent, we don't even create it

    // Front face t1
    vertices->push_back(v4);
    vertices->push_back(v5);
    vertices->push_back(v6);
    // Front face t2
    vertices->push_back(v4);
    vertices->push_back(v6);
    vertices->push_back(v7);

    // Back face t1
    vertices->push_back(v0);
    vertices->push_back(v1);
    vertices->push_back(v8);
    // Back face t2
    vertices->push_back(v1);
    vertices->push_back(v8);
    vertices->push_back(v9);

    // Top face t1
    vertices->push_back(v6);
    vertices->push_back(v7);
    vertices->push_back(v9);
    // Top face t2
    vertices->push_back(v7);
    vertices->push_back(v8);
    vertices->push_back(v9);

    // Slop face t1
    vertices->push_back(v2);
    vertices->push_back(v3);
    vertices->push_back(v5);
    // Slop face t2
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v5);

    // Right triangle face
    vertices->push_back(v2);
    vertices->push_back(v13);
    vertices->push_back(v5);

    // Right quad face t1
    vertices->push_back(v13);
    vertices->push_back(v12);
    vertices->push_back(v6);
    // Right quad face t2
    vertices->push_back(v13);
    vertices->push_back(v6);
    vertices->push_back(v5);

    // Right quad face down t1
    vertices->push_back(v1);
    vertices->push_back(v9);
    vertices->push_back(v12);
    // Right quad face down t2
    vertices->push_back(v1);
    vertices->push_back(v2);
    vertices->push_back(v12);

    // Left triangle face
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v10);

    // Left quad face t1
    vertices->push_back(v4);
    vertices->push_back(v10);
    vertices->push_back(v11);
    // Left quad face t2
    vertices->push_back(v4);
    vertices->push_back(v7);
    vertices->push_back(v11);

    // Left quad face down t1
    vertices->push_back(v0);
    vertices->push_back(v3);
    vertices->push_back(v8);
    // Left quad face down t2
    vertices->push_back(v3);
    vertices->push_back(v8);
    vertices->push_back(v11);

    // Create tile geometry
    osg::ref_ptr<osg::Geometry> tileGeometry = new osg::Geometry;

    // Match vertices
    tileGeometry->setVertexArray(vertices);

    // Add color (each rectangle has the same color except for the down one which is transparent)
    osg::Vec4 osgColor(static_cast<float>(color.red())/255.0, static_cast<float>(color.green())/255.0, static_cast<float>(color.blue())/255.0, 1.0);
    osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
    // Every face has the same color, so there is only one color
    colors->push_back(osgColor);

    // Match color
    tileGeometry->setColorArray(colors);
    tileGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);

    // Create normals
    osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(0, 0, 1));
    normals->push_back(osg::Vec3(0, 0, 1));
    double w = pw - mwp;
    double h = phm - mh;
    double norm = std::sqrt(w*w + h*h);
    normals->push_back(osg::Vec3(h/norm, 0, -w/norm));
    normals->push_back(osg::Vec3(h/norm, 0, -w/norm));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));

    // Match normals
    tileGeometry->setNormalArray(normals);
    tileGeometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);

    // Define tile 18 GL_TRIANGLES with 20*3 vertices
    tileGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, 18*3));

    // Return the tile whithout plot
    return tileGeometry.release();
}
예제 #9
0
osg::Drawable *ClampNode::createBrick(void) const {
    // Get the brick
    Clamp* clamp = static_cast<Clamp*>(_lego);
    
    // Get brick color
    QColor color = clamp->getColor();

    // Get clamp bounding box
    clamp->calculateBoundingBox();
    BoundingBox bb = clamp->getBoundingBox();
    // Get integer sizes
    int width = bb.getWidth();
    int length = bb.getLength();
    int height = bb.getHeight();

    // Get real position, according to tile size
    double mw = (-width)*Lego::length_unit/2;
    double mwpm = (-width)*Lego::length_unit/2+Lego::height_unit/2;
    double mwp = (-width)*Lego::length_unit/2+0.93*Lego::height_unit;
    double pw = (width)*Lego::length_unit/2;
    double pwm = (width)*Lego::length_unit/2-Lego::height_unit/2;
    double ml = (-length)*Lego::length_unit/2;
    double mlp = (-length+0.5)*Lego::length_unit/2;
    double pl = (length)*Lego::length_unit/2;
    double plm = (length-0.5)*Lego::length_unit/2;
    double mh = (-height)*Lego::height_unit/2;
    double mhp = (-height)*Lego::height_unit/2+2*Lego::plot_top_height;
    double mhpm = (-height)*Lego::height_unit/2+Lego::plot_top_height;
    double phm = (height)*Lego::height_unit/2-Lego::height_unit/2;
    double phmp = (height)*Lego::height_unit/2-0.5*Lego::height_unit/2;
    
    // Create 3 vertices
    osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
    osg::Vec3 v0(ml, mw, mh);
    osg::Vec3 v1(pl, mw, mh);
    osg::Vec3 v2(pl, pw, mh);
    osg::Vec3 v3(ml, pw, mh);
    osg::Vec3 v4(ml, pw, mhp);
    osg::Vec3 v5(pl, pw, mhp);
    osg::Vec3 v6(pl, mw, mhp);
    osg::Vec3 v7(ml, mw, mhp);
    osg::Vec3 v8(mlp, mw, mhp);
    osg::Vec3 v9(mlp, mw, phm);
    osg::Vec3 v10(ml, mw, phm);
    osg::Vec3 v11(ml, mwp, phmp);
    osg::Vec3 v12(mlp, mwp, phmp);
    osg::Vec3 v13(mlp, pw, mhp);
    osg::Vec3 v14(plm, mw, mhp);
    osg::Vec3 v15(plm, mw, phm);
    osg::Vec3 v16(pl, mw, phm);
    osg::Vec3 v17(pl, mwp, phmp);
    osg::Vec3 v18(plm, mwp, phmp);
    osg::Vec3 v19(plm, pw, mhp);
    osg::Vec3 v20(mlp, mwpm, mh);
    osg::Vec3 v21(plm, mwpm, mh);
    osg::Vec3 v22(plm, pwm, mh);
    osg::Vec3 v23(mlp, pwm, mh);
    osg::Vec3 v24(mlp, mwpm, mhpm);
    osg::Vec3 v25(plm, mwpm, mhpm);
    osg::Vec3 v26(plm, pwm, mhpm);
    osg::Vec3 v27(mlp, pwm, mhpm);
    
    // Create 1 faces, 0 faces are quads splitted into two triangles
    // NB: Down face is transparent, we don't even create it

    // Bottom
    vertices->push_back(v3);
    vertices->push_back(v2);
    vertices->push_back(v1);
    vertices->push_back(v0);
    // Bottom hole
    vertices->push_back(v20);
    vertices->push_back(v21);
    vertices->push_back(v22);
    vertices->push_back(v23);
    // Bottom far
    vertices->push_back(v24);
    vertices->push_back(v25);
    vertices->push_back(v26);
    vertices->push_back(v27);

    // Front face
    vertices->push_back(v2);
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v5);

    // Back face
    vertices->push_back(v0);
    vertices->push_back(v1);
    vertices->push_back(v6);
    vertices->push_back(v7);

    // Left bottom face
    vertices->push_back(v0);
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v7);

    // Right bottom face
    vertices->push_back(v1);
    vertices->push_back(v2);
    vertices->push_back(v5);
    vertices->push_back(v6);

    // Top face
    vertices->push_back(v4);
    vertices->push_back(v5);
    vertices->push_back(v6);
    vertices->push_back(v7);

    // Left part back
    vertices->push_back(v7);
    vertices->push_back(v8);
    vertices->push_back(v9);
    vertices->push_back(v10);

    // Left part left ext
    vertices->push_back(v4);
    vertices->push_back(v7);
    vertices->push_back(v10);
    vertices->push_back(v11);

    // Left part front
    vertices->push_back(v4);
    vertices->push_back(v11);
    vertices->push_back(v12);
    vertices->push_back(v13);

    // Left part left int
    vertices->push_back(v8);
    vertices->push_back(v9);
    vertices->push_back(v12);
    vertices->push_back(v13);

    // Right part back
    vertices->push_back(v6);
    vertices->push_back(v14);
    vertices->push_back(v15);
    vertices->push_back(v16);

    // Left part left ext
    vertices->push_back(v5);
    vertices->push_back(v6);
    vertices->push_back(v16);
    vertices->push_back(v17);

    // Left part front
    vertices->push_back(v5);
    vertices->push_back(v17);
    vertices->push_back(v18);
    vertices->push_back(v19);

    // Left part left int
    vertices->push_back(v14);
    vertices->push_back(v15);
    vertices->push_back(v18);
    vertices->push_back(v19);

    // Bottom front
    vertices->push_back(v20);
    vertices->push_back(v21);
    vertices->push_back(v25);
    vertices->push_back(v24);

    // Bottom right
    vertices->push_back(v21);
    vertices->push_back(v22);
    vertices->push_back(v26);
    vertices->push_back(v25);

    // Bottom back
    vertices->push_back(v22);
    vertices->push_back(v23);
    vertices->push_back(v27);
    vertices->push_back(v26);

    // Bottom left
    vertices->push_back(v23);
    vertices->push_back(v20);
    vertices->push_back(v24);
    vertices->push_back(v27);

    // Create tile geometry
    osg::ref_ptr<osg::Geometry> clampGeometry = new osg::Geometry;
    
    // Match vertices
    clampGeometry->setVertexArray(vertices);
    
    // Create colors
    osg::Vec4 osgColor(static_cast<float>(color.red())/255.0, static_cast<float>(color.green())/255.0, static_cast<float>(color.blue())/255.0, 1.0);
    osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
    // Every face has the same color, so there is only one color
    colors->push_back(osgColor);
    
    // Match color
    clampGeometry->setColorArray(colors);
    clampGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
    
    // Create normals
    osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
    normals->push_back(osg::Vec3(0, 0, -1));
    normals->push_back(osg::Vec3(0, 0, -1));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(0, 0, 1));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    double w = pw - mwp;
    double h = phmp - mhp;
    double norm = std::sqrt(w*w + h*h);
    normals->push_back(osg::Vec3(0, h/norm, w/norm));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(0, h/norm, w/norm));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    
    // Match normals
    clampGeometry->setNormalArray(normals);
    clampGeometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);

    // Define 1 GL_QUADS with 1*4 vertices, corresponding to bottom part
    clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0*4, 4));

    // Define 1 GL_QUADS with 1*4 vertices, corresponding to 1 hole in bottom part
    clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 1*4, 4));

    // Retesslate to create hole
    osgUtil::Tessellator tesslator;
    tesslator.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
    tesslator.setWindingType(osgUtil::Tessellator::TESS_WINDING_ODD);
    tesslator.retessellatePolygons(*clampGeometry);

    // Create 17 GL_QUADS, i.e. 18*4 vertices
    clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 2*4, 18*4));

    // Return the tile whithout plot
    return clampGeometry.release();
}
void
dmz::StarfighterPluginSpaceBoxOSG::_create_box () {

   const String ImageName (_rc.find_file (_imgRc));

   osg::ref_ptr<osg::Image> img =
      (ImageName ? osgDB::readImageFile (ImageName.get_buffer ()) : 0);

   if (img.valid ()) {

      osg::Geode* geode = new osg::Geode ();

      osg::Geometry* geom = new osg::Geometry;

      osg::Vec4Array* colors = new osg::Vec4Array;
      colors->push_back (osg::Vec4 (1.0f, 1.0f, 1.0f, 1.0f));
      geom->setColorArray (colors);
      geom->setColorBinding (osg::Geometry::BIND_OVERALL);

      osg::StateSet *stateset = geom->getOrCreateStateSet ();
      stateset->setMode (GL_BLEND, osg::StateAttribute::ON);

#if 0
      osg::ref_ptr<osg::Material> material = new osg::Material;

      material->setEmission (
         osg::Material::FRONT_AND_BACK,
         osg::Vec4 (1.0, 1.0, 1.0, 1.0));

      stateset->setAttributeAndModes (material.get (), osg::StateAttribute::ON);
#endif

      osg::Texture2D *tex = new osg::Texture2D (img.get ());
      tex->setWrap (osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT);
      tex->setWrap (osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT);

      stateset->setTextureAttributeAndModes (0, tex, osg::StateAttribute::ON);

      stateset->setAttributeAndModes (new osg::CullFace (osg::CullFace::BACK));

      osg::Vec3Array *vertices = new osg::Vec3Array;
      osg::Vec2Array *tcoords = new osg::Vec2Array;
      osg::Vec3Array* normals = new osg::Vec3Array;

      const float Off (_offset);

      osg::Vec3 v1 (-Off, -Off, -Off);
      osg::Vec3 v2 ( Off, -Off, -Off);
      osg::Vec3 v3 ( Off,  Off, -Off);
      osg::Vec3 v4 (-Off,  Off, -Off);
      osg::Vec3 v5 (-Off, -Off,  Off);
      osg::Vec3 v6 ( Off, -Off,  Off);
      osg::Vec3 v7 ( Off,  Off,  Off);
      osg::Vec3 v8 (-Off,  Off,  Off);

      osg::Vec3 n1 ( 1.0,  1.0,  1.0);
      osg::Vec3 n2 (-1.0,  1.0,  1.0);
      osg::Vec3 n3 (-1.0, -1.0,  1.0);
      osg::Vec3 n4 ( 1.0, -1.0,  1.0);
      osg::Vec3 n5 ( 1.0,  1.0, -1.0);
      osg::Vec3 n6 (-1.0,  1.0, -1.0);
      osg::Vec3 n7 (-1.0, -1.0, -1.0);
      osg::Vec3 n8 ( 1.0, -1.0, -1.0);

      n1.normalize ();
      n2.normalize ();
      n3.normalize ();
      n4.normalize ();
      n5.normalize ();
      n6.normalize ();
      n7.normalize ();
      n8.normalize ();

//      const float F1 (5.0f);
//      const float F2 (2.5f);
      const float F1 (5.0f);
      const float F2 (2.5f);
      int count = 0;

      // 1
      vertices->push_back (v1);
      vertices->push_back (v2);
      vertices->push_back (v3);
      vertices->push_back (v4);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n1);
      normals->push_back (n2);
      normals->push_back (n3);
      normals->push_back (n4);
      count += 4;

      // 2
      vertices->push_back (v4);
      vertices->push_back (v3);
      vertices->push_back (v7);
      vertices->push_back (v8);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n4);
      normals->push_back (n3);
      normals->push_back (n7);
      normals->push_back (n8);
      count += 4;

      // 3
      vertices->push_back (v8);
      vertices->push_back (v7);
      vertices->push_back (v6);
      vertices->push_back (v5);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n8);
      normals->push_back (n7);
      normals->push_back (n6);
      normals->push_back (n5);
      count += 4;

      // 4
      vertices->push_back (v5);
      vertices->push_back (v6);
      vertices->push_back (v2);
      vertices->push_back (v1);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n5);
      normals->push_back (n6);
      normals->push_back (n2);
      normals->push_back (n1);
      count += 4;

      // 5
      vertices->push_back (v3);
      vertices->push_back (v2);
      vertices->push_back (v6);
      vertices->push_back (v7);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n3);
      normals->push_back (n2);
      normals->push_back (n6);
      normals->push_back (n7);
      count += 4;

      // 6
      vertices->push_back (v1);
      vertices->push_back (v4);
      vertices->push_back (v8);
      vertices->push_back (v5);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n1);
      normals->push_back (n4);
      normals->push_back (n8);
      normals->push_back (n5);
      count += 4;

      geom->setNormalArray (normals);
      geom->setNormalBinding (osg::Geometry::BIND_PER_VERTEX);
      geom->addPrimitiveSet (new osg::DrawArrays (GL_QUADS, 0, count));
      geom->setVertexArray (vertices);
      geom->setTexCoordArray (0, tcoords);
      geode->addDrawable (geom);

      _box = new osg::MatrixTransform ();

      _box->addChild (geode);
   }
   else { _log.error << "Failed to load: " << _imgRc << ":" << ImageName << endl; }
}
예제 #11
0
int testVector() {
	int numErr = 0;

	logMessage(_T("TESTING  -  class GM_3dVector ...\n\n"));

	// Default constructor, vector must be invalid
	GM_3dVector v;
	if (v.isValid()) {
		logMessage(_T("\tERROR - Default constructor creates valid vector\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Default constructor creates invalid vector\n"));
	}

	// Get/Set vector coordinates
	double x = getRandomDouble();
	double y = getRandomDouble();
	double z = getRandomDouble();
	v.x(x); v.y(y); v.z(z);
	if (!v.isValid() || v.x() != x || v.y() != y || v.z() != z) {
		logMessage(_T("\tERROR - Get/Set not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Get/Set working\n"));
	}

	// Copy constructor
	GM_3dVector v1(v);
	if (v.isValid() != v1.isValid() || v1.x() != v.x() || v1.y() != v.y() || v1.z() != v.z()) {
		logMessage(_T("\tERROR - Copy constructor not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Copy constructor working\n"));
	}

	// Constructor (point)
	GM_3dPoint pt(getRandomDouble(), getRandomDouble(), getRandomDouble());
	GM_3dVector v2(pt);
	if (!v2.isValid() || v2.x() != pt.x() || v2.y() != pt.y() || v2.z() != pt.z()) {
		logMessage(_T("\tERROR - Constructor from point not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Constructor from point working\n"));
	}

	// Constructor (line)
	GM_3dLine line(getRandomDouble(), getRandomDouble(), getRandomDouble(), getRandomDouble(), getRandomDouble(), getRandomDouble());
	GM_3dVector v3(line);
	if (!v3.isValid() || v3.x() != line.end().x() - line.begin().x() || v3.y() != line.end().y() - line.begin().y() || v3.z() != line.end().z() - line.begin().z()) {
		logMessage(_T("\tERROR - Constructor from line not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Constructor from line working\n"));
	}

	// Constructor (angle)
	double ang = getRandomAngle();
	GM_3dVector v4(ang);
	if (!v4.isValid() || v4.x() != cos(ang) || v4.y() != sin(ang) || v4.z() != 0.0) {
		logMessage(_T("\tERROR - XY angle constructor not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - XY angle constructor working\n"));
	}

	// Module
	double module = v.mod();
	if (module != sqrt(v.x()*v.x() + v.y()*v.y() + v.z()*v.z())) {
		logMessage(_T("\tERROR - Module computation not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Module computation working\n"));
	}

	// Normalization
	v.normalize();
	if (fabs(v.mod()-1.0) > GM_NULL_TOLERANCE) {
		logMessage(_T("\tERROR - Normalization not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Normalization working\n"));
	}

	// xy Angle
	double checkAng = v4.xyAngle();
	if (checkAng > GM_PI) {
		checkAng -= 2.0 * GM_PI;
	}
	if (fabs(checkAng - ang) > GM_NULL_TOLERANCE) {
		logMessage(_T("\tERROR - xy angle computation not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - xy angle computation working\n"));
	}

	// Angle between vectors
	ang = getRandomAngle();
	GM_3dVector v5(ang);
	GM_3dVector baseVect(0.0);
	checkAng = baseVect.xyAngle(v5);
	if (checkAng > GM_PI) {
		checkAng -= 2.0 * GM_PI;
	}
	double checkAng1 = v5.xyAngle(baseVect);
	if (checkAng1 > GM_PI) {
		checkAng1 -= 2.0 * GM_PI;
	}
	if (fabs(checkAng - ang) > GM_NULL_TOLERANCE || fabs(-checkAng1 - ang) > GM_NULL_TOLERANCE) {
		logMessage(_T("\tERROR - Angle between vectors computation not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Angle between vectors computation working\n"));
	}

	// At left
	ang = getRandomAngle();
	if (ang < 0.0) {
		ang = 2.0 * GM_PI + ang;
	}
	double ang1 = getRandomAngle();
	if (ang1 < 0.0) {
		ang1 = 2.0 * GM_PI + ang1;
	}
	GM_3dVector v6(ang);
	GM_3dVector v7(ang1);
	bool v6AtLeftv7 = v6.isAtLeftOnXY(v7);
	bool v7AtLeftv6 = v7.isAtLeftOnXY(v6);
	double checkv6Ang = v6.xyAngle();
	double checkv7Ang = v7.xyAngle();
	bool checkv6AtLeftv7 = ang > ang1 ? true : false;
	if (fabs(ang - checkv6Ang) > GM_NULL_TOLERANCE || fabs(ang1 - checkv7Ang) > GM_NULL_TOLERANCE || checkv6AtLeftv7 != v6AtLeftv7 || v6AtLeftv7 == v7AtLeftv6) {
		logMessage(_T("\tERROR - At left not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - At left working\n"));
	}

	// Dot product
	GM_3dVector v8(getRandomDouble(), getRandomDouble(), getRandomDouble());
	GM_3dVector v9(getRandomDouble(), getRandomDouble(), getRandomDouble());
	double dotProd = v8 * v9;
	double dotProd1 = v9 * v8;
	double checkDotProd = v8.x()*v9.x() + v8.y()*v9.y() + v8.z()*v9.z();
	if (dotProd != checkDotProd || dotProd1 != checkDotProd) {
		logMessage(_T("\tERROR - Dot product not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Dot product working\n"));
	}

	// Cross product
	GM_3dVector crossProd = v8 ^ v9;
	GM_3dVector crossProd1 = v9 ^ v8;
	double checkCrossProdX = v8.y()*v9.z() - v8.z()*v9.y();
	double checkCrossProdY = v8.z()*v9.x() - v8.x()*v9.z();
	double checkCrossProdZ = v8.x()*v9.y() - v8.y()*v9.x();
	if (crossProd.x() != checkCrossProdX || crossProd.y() != checkCrossProdY || crossProd.z() != checkCrossProdZ ||
		crossProd1.x() != -checkCrossProdX || crossProd1.y() != -checkCrossProdY || crossProd1.z() != -checkCrossProdZ) {
		logMessage(_T("\tERROR - Cross product not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Cross product working\n"));
	}

	// Scale
	double factor = getRandomDouble();
	GM_3dVector v8Scaled = v8 * factor;
	if (v8Scaled.x() != v8.x()*factor || v8Scaled.y() != v8.y()*factor || v8Scaled.z() != v8.z()*factor) {
		logMessage(_T("\tERROR - Scaling not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Scaling working\n"));
	}

	// Sum
	GM_3dVector sum = v8 + v9;
	if (sum.x() != v8.x()+v9.x() || sum.y() != v8.y()+v9.y() || sum.z() != v8.z()+v9.z()) {
		logMessage(_T("\tERROR - Sum not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Sum working\n"));
	}

	// Difference
	GM_3dVector diff = v8 - v9;
	if (diff.x() != v8.x()-v9.x() || diff.y() != v8.y()-v9.y() || diff.z() != v8.z()-v9.z()) {
		logMessage(_T("\tERROR - Difference not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Difference working\n"));
	}

	return numErr;
}
예제 #12
0
void run()
{
    typedef boost::variant<int, move_copy_conting_class> variant_I_type;
    variant_I_type v1, v2;
    
    // Assuring that `move_copy_conting_class` was not created
    BOOST_CHECK(move_copy_conting_class::copy_count == 0);
    BOOST_CHECK(move_copy_conting_class::moves_count == 0);
    
    v1 = move_copy_conting_class();
    // Assuring that `move_copy_conting_class` was moved at least once
    BOOST_CHECK(move_copy_conting_class::moves_count != 0);
    
    unsigned int total_count = move_copy_conting_class::moves_count + move_copy_conting_class::copy_count;
    move_copy_conting_class var;
    v1 = 0;
    move_copy_conting_class::moves_count = 0;
    move_copy_conting_class::copy_count = 0;
    v1 = var;
    // Assuring that move assignment operator moves/copyes value not more times than copy assignment operator
    BOOST_CHECK(total_count <= move_copy_conting_class::moves_count + move_copy_conting_class::copy_count);

    move_copy_conting_class::moves_count = 0;
    move_copy_conting_class::copy_count = 0;
    v2 = static_cast<variant_I_type&&>(v1);
    // Assuring that `move_copy_conting_class` in v1 was moved at least once and was not copied
    BOOST_CHECK(move_copy_conting_class::moves_count != 0);
    BOOST_CHECK(move_copy_conting_class::copy_count == 0);

    v1 = move_copy_conting_class();
    move_copy_conting_class::moves_count = 0;
    move_copy_conting_class::copy_count = 0;
    v2 = static_cast<variant_I_type&&>(v1);
    // Assuring that `move_copy_conting_class` in v1 was moved at least once and was not copied
    BOOST_CHECK(move_copy_conting_class::moves_count != 0);
    BOOST_CHECK(move_copy_conting_class::copy_count == 0);
    total_count = move_copy_conting_class::moves_count + move_copy_conting_class::copy_count;
    move_copy_conting_class::moves_count = 0;
    move_copy_conting_class::copy_count = 0;
    v1 = v2;
    // Assuring that move assignment operator moves/copyes value not more times than copy assignment operator
    BOOST_CHECK(total_count <= move_copy_conting_class::moves_count + move_copy_conting_class::copy_count);


    typedef boost::variant<move_copy_conting_class, int> variant_II_type;
    variant_II_type v3;
    move_copy_conting_class::moves_count = 0;
    move_copy_conting_class::copy_count = 0;
    v1 = static_cast<variant_II_type&&>(v3);
    // Assuring that `move_copy_conting_class` in v3 was moved at least once (v1 and v3 have different types)
    BOOST_CHECK(move_copy_conting_class::moves_count != 0);

    move_copy_conting_class::moves_count = 0;
    move_copy_conting_class::copy_count = 0;
    v2 = static_cast<variant_I_type&&>(v1);
    // Assuring that `move_copy_conting_class` in v1 was moved at least once (v1 and v3 have different types)
    BOOST_CHECK(move_copy_conting_class::moves_count != 0);

    move_copy_conting_class::moves_count = 0;
    move_copy_conting_class::copy_count = 0;
    variant_I_type v5(static_cast<variant_I_type&&>(v1));
    // Assuring that `move_copy_conting_class` in v1 was moved at least once and was not copied
    BOOST_CHECK(move_copy_conting_class::moves_count != 0);
    BOOST_CHECK(move_copy_conting_class::copy_count == 0);

    total_count = move_copy_conting_class::moves_count + move_copy_conting_class::copy_count;
    move_copy_conting_class::moves_count = 0;
    move_copy_conting_class::copy_count = 0;
    variant_I_type v6(v1);
    // Assuring that move constructor moves/copyes value not more times than copy constructor
    BOOST_CHECK(total_count <= move_copy_conting_class::moves_count + move_copy_conting_class::copy_count);
}