コード例 #1
0
ファイル: scene_object.cpp プロジェクト: vinkle/Raytracer
// Slow method to do object-ray intersection ..
bool Pawn::test_intersect(ray3D& ray)
{
	vector<vec3> verts;
	pawnObj.getVertices(verts);
	vector<vec3> normals;
	pawnObj.getVertexNormals(normals);
	vector<uvec3> elements;
	pawnObj.getElements(elements);
	vec3 minBB, maxBB;
	pawnObj.boundingBox(minBB, maxBB);
	
	vector<vec3> vertices_tr(3);
	vector<vec3> normals_tr(3);
	if(rayBoxIntersection(ray, minBB, maxBB))
	{
		for(int i = 0; i < elements.size(); i++)
		{
			vertices_tr[0] = verts[elements[i].x]; 
			vertices_tr[1] = verts[elements[i].y];
			vertices_tr[2] = verts[elements[i].z];
			normals_tr[0]  = normals[elements[i].x]; 
			normals_tr[1]  = normals[elements[i].y];
			normals_tr[2]  = normals[elements[i].z]; 
			rayTriangleIntersection(ray, vertices_tr, normals_tr);
		}
	}
	return(!ray.intersection.none);
}
コード例 #2
0
ファイル: trk2dictionary_c.cpp プロジェクト: barakovic/COMMIT
void fiberForwardModel( float fiber[3][MAX_FIB_LEN], unsigned int pts )
{
    static Vector<double> S1, S2, S1m, S2m, P;
    static Vector<double> vox, vmin, vmax, dir;
    static double         len, t;
    static int            i, j, k;

    FiberSegments.clear();
    for(i=nPointsToSkip; i<pts-1-nPointsToSkip ;i++)
    {
        // original segment to be processed
        S1.Set( fiber[0][i]   + fiberShiftXmm, fiber[1][i]   + fiberShiftYmm, fiber[2][i]   + fiberShiftZmm );
        S2.Set( fiber[0][i+1] + fiberShiftXmm, fiber[1][i+1] + fiberShiftYmm, fiber[2][i+1] + fiberShiftZmm );

        // get a normal to the vector to move
        dir.x = S2.x-S1.x;
        dir.y = S2.y-S1.y;
        dir.z = S2.z-S1.z;
        dir.Normalize();
        if ( doIntersect==false )
            segmentForwardModel( S1, S2 );
        else
            while( 1 )
            {
                len = sqrt( pow(S2.x-S1.x,2) + pow(S2.y-S1.y,2) + pow(S2.z-S1.z,2) ); // in mm
                if ( len <= minSegLen )
                    break;

                // compute AABB of the first point (in mm)
                vmin.x = floor( (S1.x + 1e-6*dir.x)/pixdim.x ) * pixdim.x;
                vmin.y = floor( (S1.y + 1e-6*dir.y)/pixdim.y ) * pixdim.y;
                vmin.z = floor( (S1.z + 1e-6*dir.z)/pixdim.z ) * pixdim.z;
                vmax.x = vmin.x + pixdim.x;
                vmax.y = vmin.y + pixdim.y;
                vmax.z = vmin.z + pixdim.z;

                if ( rayBoxIntersection( S1, dir, vmin, vmax, t ) && t>0 && t<len )
                {
                    // add the portion S1P, and then reiterate
                    P.Set( S1.x + t*dir.x, S1.y + t*dir.y, S1.z + t*dir.z );
                    segmentForwardModel( S1, P );
                    S1.Set( P.x, P.y, P.z );
                }
                else
                {
                    // add the segment S1S2 and stop iterating
                    segmentForwardModel( S1, S2 );
                    break;
                }
            }
    }
}
コード例 #3
0
ファイル: objects.cpp プロジェクト: spillow/Samples
void Octree::traverseOctree(BoundingBox** Box, Ray ray)
{
  if ( (*Box) == NULL )
		return;

	//ray box intersection (if ray does not intersect box, return)
	clock_t start2, finish2;
	start2 = clock();
	bool rayBox = rayBoxIntersection(**Box, ray);
	finish2 = clock();
  traverse_time2 += (finish2-start2) / (double)CLOCKS_PER_SEC;
  //if ( !rayBoxIntersection(**Box, ray) )
	if ( !rayBox )
	{
		return;
	}

	if ( (*Box)->childBoxes[0] == NULL ) //then this is a leaf node
	{
    //numObjectsToSendBack += (*Box)->numObjects;
    //add to the pot (if the object isn't tagged as already been added)
    for (int i=0; i < (*Box)->Storage.size(); i++)
		{
			if ( !((*Box)->Storage[i]->beenChecked) )
			{
				objectsToSendBack.push_back( (*Box)->Storage[i] );
				(*Box)->Storage[i]->beenChecked = true;
			}
		}
    return;
	}
  
	for (int i=0; i < 8; i++)
	{
		traverseOctree(&((*Box)->childBoxes[i]),ray);
	}
}