当前位置: 首页>>代码示例>>C++>>正文


C++ Point3::Set方法代码示例

本文整理汇总了C++中Point3::Set方法的典型用法代码示例。如果您正苦于以下问题:C++ Point3::Set方法的具体用法?C++ Point3::Set怎么用?C++ Point3::Set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Point3的用法示例。


在下文中一共展示了Point3::Set方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetFade

Box3 plDistribComponent_old::GetFade()
{
    Point3 pmin;
    if( fCompPB->GetInt(kFadeInActive) )
    {
        pmin.Set(fCompPB->GetFloat(kFadeInTran), fCompPB->GetFloat(kFadeInOpaq), 0);
        if( pmin[0] == pmin[1] )
            pmin[2] = 0;
        else if( pmin[0] < pmin[1] )
            pmin[2] = -1.f;
        else
            pmin[2] = 1.f;
    }
    else
    {
        pmin.Set(0.f,0.f,0.f);
    }

    Point3 pmax;
    pmax.Set(fCompPB->GetFloat(kFadeOutTran), fCompPB->GetFloat(kFadeOutOpaq), 0);
    if( pmax[0] == pmax[1] )
        pmax[2] = 0;
    else if( pmax[0] < pmax[1] )
        pmax[2] = -1.f;
    else
        pmax[2] = 1.f;

    return Box3(pmin, pmax);
}
开发者ID:cwalther,项目名称:Plasma-nobink-test,代码行数:29,代码来源:plDistribComponent_old.cpp

示例2: GetPosRotScale

/**
*  @brief
*    Returns the position, rotation and scale of the scene node at a given time
*/
void PLSceneNode::GetPosRotScale(Point3 &vPos, Quat &qRot, Point3 &vScale, TimeValue nTime)
{
	if (m_pIGameNode) {
		// Get the position, rotation and scale - relative to the parent node
		GMatrix mParentMatrix;
		IGameNode *pIGameNodeParent = m_pIGameNode->GetNodeParent();
		if (pIGameNodeParent)
			mParentMatrix = pIGameNodeParent->GetWorldTM(nTime);
		PLTools::GetPosRotScale(m_pIGameNode->GetWorldTM(nTime)*PLTools::Inverse(mParentMatrix), vPos, qRot, vScale, IsRotationFlipped());

		// Get the scale (NOT done for special nodes!)
		if (m_nType != TypeContainer && m_nType != TypeScene && m_nType != TypeCell &&
			m_nType != TypeCamera && m_nType != TypeLight) {
			// [TODO] Do we still need this hint?
			// Check for none uniform scale
//			if (m_vScale.x != m_vScale.y || m_vScale.x != m_vScale.z || m_vScale.y != m_vScale.z) {
				// We have to use '%e' because else we may get output like '(1 1 1) is no uniform scale'
				// g_pLog->LogFLine(PLLog::Hint, "Node '%s' has a none uniform scale. (%e %e %e) This 'may' cause problems in special situations...", m_sName.c_str(), m_vScale.x, m_vScale.y, m_vScale.z);
//			}
		} else {
			// Set scale to 1
			vScale.Set(1.0f, 1.0f, 1.0f);
		}
	}
}
开发者ID:ByeDream,项目名称:pixellight,代码行数:29,代码来源:PLSceneNode.cpp

示例3: return

    // /////////////////////////////////////////////////////////////////
    //
    // /////////////////////////////////////////////////////////////////
    bool SetPoint3FromLua(const LuaPlus::LuaObject &posData, Point3 &position)
    {
        if(!posData.IsTable()) {
            return (false);
        }

        LuaPlus::LuaObject xData = posData["x"];
        LuaPlus::LuaObject yData = posData["y"];
        LuaPlus::LuaObject zData = posData["z"];

        if(!xData.IsNumber() || !yData.IsNumber() || !zData.IsNumber()) {
            return (false);
        }

        F32 x = static_cast<F32>(xData.GetNumber());
        F32 y = static_cast<F32>(yData.GetNumber());
        F32 z = static_cast<F32>(zData.GetNumber());
        position.Set(x, y, z);

        return (true);
    }
开发者ID:pjohalloran,项目名称:gameframework,代码行数:24,代码来源:LuaStateManager.cpp

示例4: Shade

Color MtlBlinn::Shade(const Cone &ray, const HitInfo &hInfo, const LightList &lights, int bounceCount) const{
    float bias = BIAS_SHADING;
    Color shade;
    Color rShade = Color(0,0,0);
    Color tShade = Color(0,0,0);
    const Material *mat;
    mat = hInfo.node->GetMaterial();
    const MtlBlinn* mb =static_cast<const MtlBlinn*>(mat);
//    cout<<"HInfo front: "<<hInfo.front<<endl;
    /* local copy */
    Point3 P;
    P.Set(hInfo.p.x,hInfo.p.y,hInfo.p.z);
    Cone iRay = ray;
    
    Color ambInt = mb->diffuse.Sample(hInfo.uvw, hInfo.duvw);
    Color allOther = Color(0,0,0);
    Color diffuse = mb->diffuse.Sample(hInfo.uvw, hInfo.duvw);
    Color ambComponent = Color(0,0,0);
    Point3 newN = hInfo.N;
    
    
    for ( unsigned int i=0; i<lights.size(); i++ ) {
        if(lights[i]->IsAmbient()){
//            cout<<"ambient "<<endl;
            Color intensity = lights[i]->Illuminate(hInfo.p);
            ambComponent += (ambInt * intensity);
            continue;
        }
        else{
//            cout<<"other lighting  "<<endl;
            Point3 L = -lights[i]->Direction(P);
            L.Normalize();
            
            Point3 V = ray.p - P;
            V.Normalize();
            
            Point3 LplusV = L + V;
            Point3 H = (L+V)/LplusV.Length();
            H.Normalize();
            
            float alpha = mb->glossiness;
//            Point3 N = hInfo.N;
            Point3 N = newN;
            float S = H.Dot(N);
            S = pow(S,alpha);
            float costheta = L.Dot(N)/(L.Length() * N.Length());
            Color intensity = lights[i]->Illuminate(P);
//            cout<<"costheta "<<endl;
            allOther += intensity * (costheta>0?costheta:0) * (diffuse + S * (mb->specular.Sample(hInfo.uvw, hInfo.duvw))) ;
        }
        /* finally add inta*cola + intall*costheta*(cold + s* colS)*/
        shade = ambComponent  + allOther;
    }
    
    /* Calculate refraction */
    if(refraction.GetColor().r>0 && bounceCount>0){
        //compute new jittered normal
        float gloss = refractionGlossiness;
        if(gloss){
            float random = rand()/(float)RAND_MAX;
            float rRadius = sqrtf(random) * gloss;
            random = rand()/(float)RAND_MAX;
            float rAngle =  random * 2.0 * M_PI;
            float x = rRadius * cos(rAngle);
            float y = rRadius * sin(rAngle);
            Point3 xAxis(1,0,0), yAxis(0,1,0), v1, v2, normalDir;
            normalDir = hInfo.N;
            //    normalDir.Normalize();
            if(normalDir.Dot(xAxis) > 0.7)  v1 = normalDir.Cross(yAxis);
            else v1 = normalDir.Cross(xAxis);
            v2 = v1.Cross(normalDir);
            v1.Normalize(); v2.Normalize();
            v1 *= x;
            v2 *= y;
            
            newN = hInfo.N + v1.Length() + v2.Length();
            newN.Normalize();
        }
        else{
            newN = hInfo.N;
        }
        //-------------------------------------
        
        Color reflShade = Color(0,0,0);
        float R0, Refl = 0.0f, Trans = 0.0f;
        HitInfo temp;
        temp.Init();
        
//        Point3 N = hInfo.N;
        Point3 N = newN;
//        Point3 V = Point3(iRay.p.x -  hInfo.p.x, iRay.p.y - hInfo.p.y, iRay.p.z - hInfo.p.z);
        Point3 V = Point3(hInfo.p.x - iRay.p.x, hInfo.p.y - iRay.p.y, hInfo.p.z - iRay.p.z);
        V.Normalize();
        float n1 = 1, n2 = 1;
        if(hInfo.front){ /* Hitting from outside */
//            temp.front = false;
            n2 = ior;
//            cout<<"outside "<<endl;
        }
        else if(!hInfo.front){ /* Transmission from the inside */
//.........这里部分代码省略.........
开发者ID:varunk08,项目名称:raytracing,代码行数:101,代码来源:main.cpp

示例5: ExportQuake3Model

int ExportQuake3Model(const TCHAR *filename, ExpInterface *ei, Interface *gi, int start_time, std::list<ExportNode> lTags, std::list<ExportNode> lMeshes)
{
	FILE *file;
	int i, j, totalTags, totalMeshes, current_time = 0;
	long pos_current, totalTris = 0, totalVerts = 0;
	std::list<FrameRange>::iterator range_i;
	std::vector<Point3> lFrameBBoxMin;
	std::vector<Point3> lFrameBBoxMax;
	long pos_tagstart;
	long pos_tagend;
	long pos_filesize;
	long pos_framestart;
	int lazynamesfixed = 0;
	const Point3 x_axis(1, 0, 0);
	const Point3 z_axis(0, 0, 1);

	SceneEnumProc checkScene(ei->theScene, start_time, gi);
	totalTags = (int)lTags.size();
	if (g_tag_for_pivot)
		totalTags++;
	totalMeshes = (int)lMeshes.size();

	// open file
	file = _tfopen(filename, _T("wb"));
	if (!file)
	{
		ExportError("Cannot open file '%s'.", filename);
		return FALSE;
	}
	ExportDebug("%s:", filename);

	// sync pattern and version
	putChars("IDP3", 4, file);
	put32(15, file);
	putChars("Darkplaces MD3 Exporter", 64, file);
	put32(0, file);   // flags
	
	// MD3 header
	ExportState("Writing MD3 header");
	put32(g_total_frames, file);      // how many frames
	put32(totalTags, file);	  // tagsnum
	put32(totalMeshes, file); // meshnum
	put32(1, file);   // maxskinnum
	put32(108, file); // headersize
	pos_tagstart = ftell(file); put32(0, file);   // tagstart
	pos_tagend	= ftell(file);  put32(256, file); // tagend
	pos_filesize = ftell(file); put32(512, file); // filesize
	ExportDebug("    %i frames, %i tags, %i meshes", g_total_frames, totalTags, totalMeshes);

	// frame info
	// bbox arrays get filled while exported mesh and written back then
	ExportState("Writing frame info");
	pos_framestart = ftell(file);
	lFrameBBoxMin.resize(g_total_frames);
	lFrameBBoxMax.resize(g_total_frames);
	for (i = 0; i < g_total_frames; i++)
	{
		// init frame data
		lFrameBBoxMin[i].Set(0, 0, 0);
		lFrameBBoxMax[i].Set(0, 0, 0);
		// put data
		putFloat(-1.0f, file); // bbox min vector
		putFloat(-1.0f, file);
		putFloat(-1.0f, file);	
		putFloat( 1.0f, file); // bbox max vector
		putFloat(1.0f, file);
		putFloat(1.0f, file);
		putFloat(0.0f, file);  // local origin (usually 0 0 0)
		putFloat(0.0f, file);
		putFloat(0.0f, file);
		putFloat(1.0f, file);  // radius of bounding sphere
		putChars("", 16, file);
	}

	// tags
	pos_current = ftell(file);
	fseek(file, pos_tagstart, SEEK_SET);
	put32(pos_current, file);
	fseek(file, pos_current, SEEK_SET);
	
	// for each frame range cycle all frames and write out each tag
	long pos_tags = pos_current;
	if (totalTags)
	{
		long current_frame = 0;
		ExportState("Writing %i tags", totalTags);
		for (range_i = g_frame_ranges.begin(); range_i != g_frame_ranges.end(); range_i++)
		{
			for (i = (*range_i).first; i <= (int)(*range_i).last; i++, current_frame++)
			{
				SceneEnumProc current_scene(ei->theScene, i * g_ticks_per_frame, gi);
				current_time = current_scene.time;

				// write out tags
				if (lTags.size())
				{
					for (std::list<ExportNode>::iterator tag_i = lTags.begin(); tag_i != lTags.end(); tag_i++)
					{
						INode *node	= current_scene[tag_i->i]->node;
						Matrix3	tm = node->GetObjTMAfterWSM(current_time);
//.........这里部分代码省略.........
开发者ID:paulvortex,项目名称:MaxDpMd3Exporter,代码行数:101,代码来源:ExportMD3.cpp

示例6: Shade

Color MtlBlinn::Shade(const Ray &ray, const HitInfo &hInfo, const LightList &lights, int bounceCount) const{
    float bias = BIAS_SHADING;
    Color shade;
    Color rShade = Color(0,0,0);
    Color tShade = Color(0,0,0);
    const Material *mat;
    mat = hInfo.node->GetMaterial();
    const MtlBlinn* mb =static_cast<const MtlBlinn*>(mat);
//    cout<<"HInfo front: "<<hInfo.front<<endl;
    /* local copy */
    Point3 P;
    P.Set(hInfo.p.x,hInfo.p.y,hInfo.p.z);
    Ray iRay = ray;
    
    Color ambInt = mb->diffuse;
    Color allOther = Color(0,0,0);
    Color diffuse = mb->diffuse;;
    Color ambComponent = Color(0,0,0);
    
    for ( unsigned int i=0; i<lights.size(); i++ ) {
        if(lights[i]->IsAmbient()){
//            cout<<"ambient "<<endl;
            Color intensity = lights[i]->Illuminate(hInfo.p);
            ambComponent += (ambInt * intensity);
            continue;
        }
        else{
//            cout<<"other lighting  "<<endl;
            Point3 L = -lights[i]->Direction(P);
            L.Normalize();
            
            Point3 V = ray.p - P;
            V.Normalize();
            
            Point3 LplusV = L + V;
            Point3 H = (L+V)/LplusV.Length();
            H.Normalize();
            
            float alpha = mb->glossiness;
            Point3 N = hInfo.N;
            float S = H.Dot(N);
            S = pow(S,alpha);
            float costheta = L.Dot(N)/(L.Length() * N.Length());
            Color intensity = lights[i]->Illuminate(P);
//            cout<<"costheta "<<endl;
            allOther += intensity * (costheta>0?costheta:0) * (diffuse + S * (mb->specular)) ;
        }
        /* finally add inta*cola + intall*costheta*(cold + s* colS)*/
        shade = ambComponent  + allOther;
    }
    
    /* Calculate refraction */
    if(refraction.Grey()>0 && bounceCount>0){
        Color reflShade = Color(0,0,0);
        float R0, Refl = 0.0f, Trans = 0.0f;
        HitInfo temp;
        temp.Init();
        
        Point3 N = hInfo.N;
//        Point3 V = Point3(iRay.p.x -  hInfo.p.x, iRay.p.y - hInfo.p.y, iRay.p.z - hInfo.p.z);
        Point3 V = Point3(hInfo.p.x - iRay.p.x, hInfo.p.y - iRay.p.y, hInfo.p.z - iRay.p.z);
        V.Normalize();
        float n1 = 1, n2 = 1;
        if(hInfo.front){ /* Hitting from outside */
//            temp.front = false;
            n2 = ior;
//            cout<<"outside "<<endl;
        }
        else if(!hInfo.front){ /* Transmission from the inside */
//            temp.front = true;
            n1 = ior;
//            cout<<"intside... "<<endl;
            N = -hInfo.N;
        }
        float ratio_n = n1 / n2;
        
        float costheta_v = -V.Dot(N);        /* refer: http://graphics.stanford.edu/courses/cs148-10-summer/docs/2006--degreve--reflection_refraction.pdf */

        float sin2theta_t = ratio_n * ratio_n * (1 - costheta_v * costheta_v);
        Point3 T =   ratio_n * V + (ratio_n * costheta_v - sqrtf(1 - sin2theta_t)) * N ;
//        cout<<ratio_n<<" "<<"cos_v "<<costheta_v<<" sin2theta_t "<<sin2theta_t<<endl;
        Ray tRay = Ray(hInfo.p,T);
        
        //tRay.dir.Normalize();
        tRay.p.x = tRay.p.x + bias *tRay.dir.x; /* add bias */
        tRay.p.y = tRay.p.y + bias *tRay.dir.y;
        tRay.p.z = tRay.p.z + bias *tRay.dir.z;
//        cout<<"B temp front: "<< temp.front<<endl;
        if(sin2theta_t <= 1){
            if(RayTrace_2(tRay, temp)){
//                bounceCount--;
//                cout<<"A temp front: "<< temp.front<<endl;
                tShade  =  temp.node->GetMaterial()->Shade(tRay,temp,lights,bounceCount);
                tShade.r *= exp(-absorption.r * temp.z);
                tShade.g *= exp(-absorption.g * temp.z);
                tShade.b *= exp(-absorption.b * temp.z);
//                shade = tShade; /* remove later */
//                return shade;
               
                
//.........这里部分代码省略.........
开发者ID:varunk08,项目名称:raytracing,代码行数:101,代码来源:main.cpp

示例7: Assert

void
VectorOpsTester::Test () {

    stringstream ssError;

    try {

        Point3<float> p;
        Point3<float> q;

        p.Set( 1, 2, 3 );
        q.Set( 4, 5, 6 );
        Assert( !(p == q), "== didn't work." );
        Assert( (p != q), "!= didn't work." );
        p.Set( 1, 2, 3 );
        q.Set( 1, 2, 3 );
        Assert( (p == q), "== didn't work." );
        Assert( !(p != q), "!= didn't work." );


        const int cVals = 10;
        float vals[cVals];
        for ( int n = 0; n < cVals; n++ ) {
            vals[n] = (float)random() / (float)random();
        }

        p.Set( vals[0], vals[1], vals[2] );
        q.Set( vals[3], vals[4], vals[5] );

        float dot = VectorOps::Dot( p, q );
        Assert( (fabs( dot - (p[0] * q[0] + p[1] * q[1] + p[2] * q[2])) < 0.0001),
                "dot didn't work." );



        p.Set( 0, 0, 0 );
        q.Set( 0, 0, 3 );
        Point3<float> plane( 0, 0, 2 );
        Point3<float> n( 0, 0, 1 );
        Point3<float> x;

        VectorOps::IntersectionResult rIntersect =
            VectorOps::SegmentIntersectsPlane( p, q, plane, n, x );
        Assert( (VectorOps::intersect == rIntersect),
                "SegmentIntersectsPlane failed, incorrect result" );
        Assert( (x[0] == 0),
                "SegmentIntersectsPlane failed, x was wrong" );
        Assert( (x[1] == 0),
                "SegmentIntersectsPlane failed, x was wrong" );
        Assert( (x[2] == 2),
                "SegmentIntersectsPlane failed, x was wrong" );

        p.Set( 0, 0, 0 );
        q.Set( 0, 0, 3 );
        plane.Set( 0, 0, 4 );
        n.Set( 0, 0, 1 );
        rIntersect = VectorOps::SegmentIntersectsPlane( p, q, plane, n, x );
        Assert( (VectorOps::dontIntersect == rIntersect),
                "SegmentIntersectsPlane failed, incorrect result" );
        Assert( (x[0] == 0),
                "SegmentIntersectsPlane failed, x was wrong" );
        Assert( (x[1] == 0),
                "SegmentIntersectsPlane failed, x was wrong" );
        Assert( (x[2] == 2),
                "SegmentIntersectsPlane failed, x was wrong" );

        p.Set( 0, 0, 0 );
        q.Set( 0, 0, 1 );
        plane.Set( 0, 0, 1 );
        n.Set( 0, 1, 0 );
        rIntersect = VectorOps::SegmentIntersectsPlane( p, q, plane, n, x );
        Assert( (VectorOps::segmentInPlane == rIntersect),
                "SegmentIntersectsPlane failed, incorrect result" );
        Assert( (x[0] == 0),
                "SegmentIntersectsPlane failed, x was wrong" );
        Assert( (x[1] == 0),
                "SegmentIntersectsPlane failed, x was wrong" );
        Assert( (x[2] == 2),
                "SegmentIntersectsPlane failed, x was wrong" );

        p.Set( 0, 0, 0 );
        q.Set( 0, 0, 1 );
        plane.Set( 0, 1, 0 );
        n.Set( 0, 1, 0 );
        rIntersect = VectorOps::SegmentIntersectsPlane( p, q, plane, n, x );
        Assert( (VectorOps::segmentParallelToPlane == rIntersect),
                "SegmentIntersectsPlane failed, incorrect result" );
        Assert( (x[0] == 0),
                "SegmentIntersectsPlane failed, x was wrong" );
        Assert( (x[1] == 0),
                "SegmentIntersectsPlane failed, x was wrong" );
        Assert( (x[2] == 2),
                "SegmentIntersectsPlane failed, x was wrong" );

        p.Set( 1, 0, 0 );
        q.Set( 0, 1, 0 );
        double rads = VectorOps::RadsBetweenVectors( p, q );
        Assert( fabs(rads - M_PI/2.0) < 0.0001,
                "RadsBetweenVectors was wrong" );

//.........这里部分代码省略.........
开发者ID:guo2004131,项目名称:freesurfer,代码行数:101,代码来源:test_VectorOps.cpp

示例8: objFileRead

BOOL objFileRead(const TCHAR *filename, ImpInterface *imp){
	FILE *fp;
    int i;
	tLump  *idxtable;

	if((fp = fopen(filename, "rb")) == NULL)
		return 0;

	fseek(fp, 0, SEEK_END);
	int fileSize = ftell(fp);
	fseek(fp, 0, SEEK_SET);

	char *data = new char[fileSize];
	fread(data, fileSize, 1, fp);

	tHeader *header = (tHeader *)data;
	if(*(int*)header->strID != CMAPHEADER_ID)
		return 0;

	if(header->version != CMAPHEADER_VERSION)
		return 0;

	idxtable = (tLump *)header + 1;

	tVertex *Verts = (tVertex *)(data + idxtable[kVertices].offset);	
	int NumVerts = idxtable[kVertices].length / sizeof(tVertex);

	tFace *faces = (tFace *)(data + idxtable[kLeafFaces].offset);	
	int NumFaces = idxtable[kLeafFaces].length / sizeof(tFace);

	int *elems = (int *)(data + idxtable[kElements].offset);	
	int NumElems = idxtable[kElements].length / sizeof(int);

	tArea *mAreas = (tArea *)(data + idxtable[kAreas].offset);
    int NumAreas = idxtable[kAreas].length / sizeof(tArea);

	Point3 p;

	TriObject *object = CreateNewTriObject();
	if(!object)
		return 0;
	
	Mesh *msh = &object->GetMesh();

	msh->setNumVerts(NumVerts);

	for(i = 0 ; i < NumVerts ; i++){
		msh->setVert(i, Verts[i].point[0], -Verts[i].point[2], Verts[i].point[1]);
		p.Set(Verts[i].norm[0], -Verts[i].norm[2], Verts[i].norm[1]);
		msh->setNormal(i, p);
	}

	int face = 0;
	for(int k = 1 ; k < NumAreas ; k++){
		for(i = mAreas[k].startFace ; i < mAreas[k].startFace + mAreas[k].numOfFaces ; i++){
			for(int j = faces[i].startElement ; j < faces[i].startElement + faces[i].elementsSize ; j++){
				int k = j * 3;
				if(elems[k] < 0){
					elems[k] = 0;
					elems[k+1] = 1;
					elems[k+2] = 2;
					faces[i].vertexIndex = 0;
				}
				msh->setNumFaces(face + 1, TRUE);
				msh->faces[face].setVerts(faces[i].vertexIndex + elems[k + 0], 
											faces[i].vertexIndex + elems[k + 1], 
											faces[i].vertexIndex + elems[k + 2]);
				msh->faces[face].setEdgeVisFlags(1, 1, 1);
				face++;
			}
		}
	}
	
	delete [] data;

	fclose(fp);
	msh->buildNormals();
	msh->buildBoundingBox();
	msh->InvalidateEdgeList();

	ImpNode *node = imp->CreateNode();
	if(!node) {
		delete object;
		return 0;
	}
	Matrix3 tm;
	tm.IdentityMatrix();
	node->Reference(object);
	node->SetTransform(0,tm);
	imp->AddNodeToScene(node);
	node->SetName(_T("Sylphis map"));


    return TRUE;
}
开发者ID:harkal,项目名称:sylphis3d,代码行数:95,代码来源:cmapimp.cpp

示例9: fnSave

void
VolumeCollectionTester::Test ( Tcl_Interp* iInterp ) {

  stringstream ssError;

  try {

    string fnMRI = "test_data/bertT1.mgz";
    VolumeCollection* vol = new VolumeCollection();
    vol->SetFileName( fnMRI );
    MRI* mri = const_cast<MRI*>(vol->GetMRI());

    Assert( (vol->GetTypeDescription() == "Volume"),
            "GetTypeDescription didn't return Volume" );

    DataManager dataMgr = DataManager::GetManager();
    MRILoader mriLoader = dataMgr.GetMRILoader();
    Assert( 1 == mriLoader.CountLoaded(),
            "CountLoaded didn't return 1" );
    Assert( 1 == mriLoader.CountReferences(mri),
            "CountReferences didn't return 1" );

    char* fnMRIC = strdup( fnMRI.c_str() );
    MRI* mriComp = MRIread( fnMRIC );

    Assert( (MRImatch( mriComp, mri )), "MRImatch failed for load" );

    MRIfree( &mriComp );


    // Save it in /tmp, load it, and match it again.
    string fnSave( "/tmp/test.mgz" );
    vol->Save( fnSave );

    VolumeCollection* testVol = new VolumeCollection();
    testVol->SetFileName( fnSave );
    MRI* testMri = const_cast<MRI*>(testVol->GetMRI());
    Assert( (MRImatch( testMri, mri )), "MRImatch failed for load after save");



    // Make an ROI and make sure it's a volume ROI.
    try {
      int roiID = vol->NewROI();
      ScubaROIVolume* roi =
        dynamic_cast<ScubaROIVolume*>(&ScubaROI::FindByID( roiID ));
      roi = NULL;
    } catch (...) {
      throw( runtime_error("typecast failed for NewROI") );
    }


    // Try our conversions.
    Point3<float> world;
    Point3<float> data;
    Point3<int> index;
    world.Set( -50, 0, -80 );
    vol->RASToMRIIndex( world.xyz(), index.xyz() );
    {
      stringstream ssError;
      ssError << "RASToMRIIndex failed. world "
      << world << " index " << index;
      Assert( (index.x() == 178 && index.y() == 208 && index.z() == 128),
              ssError.str() );
    }

    // Set a transform that scales the volume up by 2x in the world.
    ScubaTransform dataTransform;
    dataTransform.SetMainTransform( 2, 0, 0, 0,
                                    0, 2, 0, 0,
                                    0, 0, 2, 0,
                                    0, 0, 0, 1 );
    vol->SetDataToWorldTransform( dataTransform.GetID() );

    world.Set( -50, 0, -80 );
    vol->RASToDataRAS( world.xyz(), data.xyz() );
    {
      stringstream ssError;
      ssError << "RASToDataRAS failed. world "
      << world << " data " << data;
      Assert( ((FEQUAL(data.x(),-25)) &&
               (FEQUAL(data.y(),0)) &&
               (FEQUAL(data.z(),-40))),
              ssError.str() );
    }

    vol->RASToMRIIndex( world.xyz(), index.xyz() );

    if ( index.x() != 153 || index.y() != 168 || index.z() != 128 ) {
      cerr << "RASToMRIIndex with data transform failed. world "
      << world << " index " << index << endl;
      throw( runtime_error( "failed" ) );
    }


    world.Set( -50, 0, -80 );
    VolumeLocation loc( vol->MakeVolumeLocationFromRAS( world.xyz() ) );
    if ( !vol->IsInBounds( loc ) ) {
      stringstream ssError;
      ssError << "IsInBounds failed. world " << world;
//.........这里部分代码省略.........
开发者ID:ewong718,项目名称:freesurfer,代码行数:101,代码来源:test_VolumeCollection.cpp


注:本文中的Point3::Set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。