コード例 #1
0
ファイル: SurfaceObj.cpp プロジェクト: pigoblock/TFYP
void SurfaceObj::rotate(Mat3x3f& rot)
{
	for(int i=0;i<Point.size();i++)
		Point[i]=rot*Point0[i];
	computeFaceNormal();
	computeCenterPoint();
};
コード例 #2
0
ファイル: Shape.cpp プロジェクト: xiaojhl/Image-2-Shape
void Shape::init(VertexList& vertexList, FaceList& faceList, STLVectorf& UVList)
{
  setVertexList(vertexList);
  setFaceList(faceList);
  setUVCoord(UVList);

  color_list.resize(vertex_list.size(), 0.5);

  std::cout<<"Building face adjacent list...\n";
  buildFaceAdj();

  std::cout<<"Building 1-ring neighbors list...\n";
  buildVertexShareFaces();

  std::cout<<"Building vertex adjacent list...\n";
  buildVertexAdj();

  std::cout << "Building edge connectivity...\n";
  computeEdgeConnectivity();

  std::cout<<"Computing bounding box...\n";
  computeBounds();

  std::cout<<"Computing face normals...\n";
  computeFaceNormal();
  computeVertexNormal();

  buildKDTree();
}
コード例 #3
0
ファイル: SurfaceObj.cpp プロジェクト: pigoblock/TFYP
void SurfaceObj::rotateC(Quat q)
{
	for(int i=0;i<Point.size();i++)
		Point[i]=q.rotate(Point[i]);
	computeCenterPoint();
	computeFaceNormal();
};
コード例 #4
0
ファイル: SurfaceObj.cpp プロジェクト: pigoblock/TFYP
void SurfaceObj::scaleC(float scale)
{
	int i;
	for(i=0;i<Point.size();i++)
	{
		Point[i]=Point[i]*scale;
	}
	computeFaceNormal();
	computeCenterPoint();
};
コード例 #5
0
ファイル: SurfaceObj.cpp プロジェクト: pigoblock/TFYP
void SurfaceObj::rotate(float* rot)
{
	Mat3x3f Rot;
	Rot(0,0)=rot[0]; Rot(0,1)=rot[1]; Rot(0,2)=rot[2];
	Rot(1,0)=rot[4]; Rot(1,1)=rot[5]; Rot(1,2)=rot[6];
	Rot(2,0)=rot[8]; Rot(2,1)=rot[9]; Rot(2,2)=rot[10];
	rotate(Rot);
	computeCenterPoint();
	computeFaceNormal();
};
コード例 #6
0
ファイル: SurfaceObj.cpp プロジェクト: pigoblock/TFYP
void SurfaceObj::rotateC(Vec3f axis, float angle)
{
	Mat3x3f rot;
	computeRotationMatrix(axis, angle, rot);

	for(int i=0;i<Point.size();i++)
		Point[i]=rot*Point[i];
	computeFaceNormal();
	computeCenterPoint();
};
コード例 #7
0
void Mesh::updateMeshData(){


	FaceVertex* from, *to;
	ofVec3f zeros;

	for(vector<Vertex*> :: iterator it = vList.begin(); it != vList.end(); it++){
		(*it)->setIncidentEdge(0);
		(*it)->setNormal(zeros);
	} 

	
	//check from face to face 
	for(map<int, Face*> :: iterator it = faces.begin(); it != faces.end(); it++){
		Face* x = (*it).second;

		x->setFaceNormal(computeFaceNormal(x));
		ofVec3f n = x->getFaceNormal();

		for(int i = 0; i < 3; i++){
			
			switch (i){
				case 0: 
				from = x->getA();
				to = x->getB();
		
				break;

				case 1: 
				from = x->getB();
				to = x->getC();
				break;

				case 2:
				from = x->getC();
				to = x->getA();
			}

			vList[from->id]->incrementIncident();
			vList[from->id]->addComponentNormal(n);

			//if it's a boundary, then make sure to add both directions
			if(!to->hasNext()){
				vList[to->id]->incrementIncident();
				vList[to->id]->addComponentNormal(n);
			} 
		}



	}

	for(vector<Vertex*> :: iterator it = vList.begin(); it != vList.end(); it++) (*it)->makeNormalAverage();

}
コード例 #8
0
ファイル: Shape.cpp プロジェクト: xiaojhl/Image-2-Shape
void Shape::updateShape(VertexList& new_vertex_list)
{
  vertex_list = new_vertex_list;

  computeFaceNormal();

  computeVertexNormal();

  computeBounds();

  buildKDTree();
}
コード例 #9
0
ファイル: SurfaceObj.cpp プロジェクト: pigoblock/TFYP
void SurfaceObj::scale(float x, float y, float z)
{
	int i;
	for(i=0;i<Point.size();i++)
	{
		Point[i][0]=Point0[i][0]*x;
		Point[i][1]=Point0[i][1]*y;
		Point[i][2]=Point0[i][2]*z;
	}
	computeFaceNormal();
	computeCenterPoint();
};
コード例 #10
0
ファイル: SurfaceObj.cpp プロジェクト: pigoblock/TFYP
void SurfaceObj::init(std::vector<Vec3f> _point, std::vector<Vec3i> _face)
{
	Point = _point;
	Face = _face;

	//Initialize topology information
	Container=new TopologyContainer;
	Container->init(&Point0, &Point, &Face, &Edge);
	Modifier=new TopologyModifier;

	//face normal vector 
	FaceNormal.resize(Face.size());
	PointNormal.resize(Point.size());

	computeFaceNormal();
	computeCenterPoint();
}
コード例 #11
0
void TriMesh::computeDivergence(const std::vector<Vec3>& faceVector, VectorXd& vertForm) const
{
    vertForm = VectorXd::Zero(numVerts());
    for (unsigned face = 0; face < numFaces(); ++face) 
    {
        std::vector<unsigned> fVert;
        getFaceVerts(face, fVert);
        assert(fVert.size() == 3);
        
        Vec3 n = computeFaceNormal(face);
        for (unsigned i = 0; i < 3; ++i) 
        {
            Vec3 p1 = getVertPos(fVert[(i+1)%3]);
            Vec3 p2 = getVertPos(fVert[(i+2)%3]);
            vertForm[fVert[i]] += 0.5*faceVector[face].dot(n.cross(p2-p1));
        }
    }
}
コード例 #12
0
void TriMesh::computeVertNormals(std::vector<Vec3>& vertNormal) const
{
    vertNormal = std::vector<Vec3>(numVerts(), Vec3::Zero());
    
    for (unsigned face = 0; face < numFaces(); ++face) 
    {
        std::vector<unsigned> fVert;
        getFaceVerts(face, fVert);
        assert(fVert.size() == 3);

        double faceArea = computeFaceArea(face);
        Vec3 faceNormal = computeFaceNormal(face);
        for (unsigned i = 0; i < 3; ++i) 
            vertNormal[fVert[i]] += faceArea * faceNormal;
    }

    for (unsigned vert = 0; vert < numVerts(); ++vert) 
    {
        vertNormal[vert].normalize();
    }
}
コード例 #13
0
ファイル: SurfaceObj.cpp プロジェクト: pigoblock/TFYP
void SurfaceObj::readObjDataSTL(const char * filePath)
{
	// Load STL
	CSTL stl;
//	AfxMessageBox(_T("herekjashf"));
	stl.ReadData(filePath);
//	AfxMessageBox(_T("here3"));

	// Assign Points
	Point0.clear();
	vec3d* pointSTL = stl.GetPoint();
	for (int i = 0; i < stl.GetPointNum(); i++)
	{
		Point0.push_back(Vec3f(pointSTL[i][0], pointSTL[i][1], pointSTL[i][2]));
	}
	Point = Point0;
//	AfxMessageBox(_T("here4"));

	// Assign Faces
	Face.clear();
	vec3i* faceSTL = stl.GetFace();
	for (int i = 0; i < stl.GetFaceNum(); i++)
	{
		Face.push_back(Vec3i(faceSTL[i][0], faceSTL[i][1], faceSTL[i][2]));
	}
//	AfxMessageBox(_T("here5"));

	//Initialize topology information
	Container=new TopologyContainer;
	Container->init(&Point0, &Point, &Face, &Edge);
	Modifier=new TopologyModifier;

	//face normal vector 
	FaceNormal.resize(Face.size());
	PointNormal.resize(Point.size());

	computeFaceNormal();
	computeCenterPoint();
//	AfxMessageBox(_T("here6"));
}
コード例 #14
0
ファイル: SurfaceObj.cpp プロジェクト: pigoblock/TFYP
void SurfaceObj::readObjData(const char* filename)
{
	FILE *fp;
	int i;
	fp = fopen(filename,"r");
	int pointNum=0;
	int faceNum=0;

	fscanf(fp,"%d\n",&pointNum);
	Point0.resize(pointNum);
	Point.resize(pointNum);
	Dis.resize(pointNum);
	PointNormal.resize(pointNum);

	for(i=0;i<pointNum;i++)
	{
		fscanf(fp,"%f %f %f\n",&Point[i][0], &Point[i][1], &Point[i][2]);
		Point0[i]=Point[i];
	}

	fscanf(fp,"%d\n",&faceNum);
	Face.resize(faceNum);
	FaceNormal.resize(faceNum);

	for(i=0;i<faceNum;i++)
	{
		fscanf(fp,"%d %d %d\n",&Face[i][0], &Face[i][1], &Face[i][2]);
	}

	//Initialize topology information
	Container=new TopologyContainer;
	Container->init(&Point0, &Point, &Face, &Edge);
	Modifier=new TopologyModifier;

	//face normal vector °è»ê
	computeFaceNormal();
	computeCenterPoint();
	fclose(fp);
}
コード例 #15
0
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void OutlineEdgeExtractor::addPrimitives(uint verticesPerPrimitive, const uint* indices, size_t indexCount)
{
    CVF_ASSERT(verticesPerPrimitive > 0);
    CVF_ASSERT(indices);
    CVF_ASSERT(indexCount > 0);

    // Points will never become edges
    if (verticesPerPrimitive < 2)
    {
        return;
    }

    size_t numPrimitives = indexCount/verticesPerPrimitive;

    size_t ip;
    for (ip = 0; ip < numPrimitives; ip++)
    {
        size_t myFaceIndex = m_faceNormals.size();
        size_t firstIdxInPrimitive = ip*verticesPerPrimitive;

        // Normal computation accepts points and lines, but in that case returns a zero vector
        Vec3f faceNormal = computeFaceNormal(&indices[firstIdxInPrimitive], verticesPerPrimitive);
        m_faceNormals.push_back(faceNormal);

        uint i;
        for (i = 0; i < verticesPerPrimitive; i++)
        {
            const uint vertexIdx1 = indices[firstIdxInPrimitive + i];
            const uint vertexIdx2 = (i < verticesPerPrimitive - 1) ? indices[firstIdxInPrimitive + i + 1] : indices[firstIdxInPrimitive];

            // Never add collapsed edges
            if (vertexIdx1 == vertexIdx2)
            {
                continue;
            }

            int64 edgeKeyVal = EdgeKey(vertexIdx1, vertexIdx2).toKeyVal();
            std::map<int64, size_t>::iterator it = m_edgeToFaceIndexMap.find(edgeKeyVal);
            if (it == m_edgeToFaceIndexMap.end())
            {
                // Not found, so add and register face index
                m_edgeToFaceIndexMap[edgeKeyVal] = myFaceIndex;
            }
            else
            {
                size_t otherFaceIdx = it->second;
                if (otherFaceIdx < OEE_MULTIREF_EDGE)
                {
                    // An edge is already there, check angle
                    if (isFaceAngleAboveThreshold(myFaceIndex, otherFaceIdx))
                    {
                        m_edgeToFaceIndexMap[edgeKeyVal] = OEE_OUTLINE_EDGE;
                    }
                    else
                    {
                        m_edgeToFaceIndexMap[edgeKeyVal] = OEE_NON_OUTLINE_EDGE;
                    }
                }
                else
                {
                    // Three or more faces share an edge
                    m_edgeToFaceIndexMap[edgeKeyVal] = OEE_MULTIREF_EDGE;
                }
            }
        }
    }
}
コード例 #16
0
ファイル: SurfaceObj.cpp プロジェクト: pigoblock/TFYP
void SurfaceObj::updateNormal()
{
	FaceNormal.resize(Face.size());
	PointNormal.resize(Point.size());
	computeFaceNormal();
}