void writeToFile(const std::string &name) {
    if (numNonZeros == 0)
      updateNumNonZeros();

    if (getNumZ() == 0 || getNumFeatures() == 0 || getNumY() == 0 ||
        getNumX() == 0 || zeroZero.norm() == 0) {
      std::cout << "[voxel::FeatureVoxel::writeToFile] Feature Voxel has unset "
                   "members"
                << std::endl;
      exit(1);
    }

    std::ofstream out(name, std::ios::out | std::ios::binary);

    int z = getNumZ();
    out.write(reinterpret_cast<const char *>(&z), sizeof(z));

    for (int k = 0; k < z; ++k)
      saveMatrixAsSparse(this->voxelGrid[k], out);

    int numFeatureVectors = this->featureVectors.size();
    out.write(reinterpret_cast<const char *>(&numFeatureVectors), sizeof(int));

    for (auto &v : this->featureVectors)
      saveSpareVector(*v, out);

    out.write(reinterpret_cast<const char *>(&nextID), sizeof(nextID));
    out.write(reinterpret_cast<const char *>(&numNonZeros),
              sizeof(numNonZeros));
    out.write(reinterpret_cast<const char *>(zeroZero.data()),
              sizeof(zeroZero));
  };
 DescripPtr getFeatureVector(int x, int y, int z) const {
   if (x < 0 || x >= getNumX())
     return NULL;
   if (y < 0 || y >= getNumY())
     return NULL;
   if (z < 0 || z >= getNumZ())
     return NULL;
   int ID = this->voxelGrid[z](y, x);
   return this->getFeatureVector(ID);
 };
Esempio n. 3
0
void NgonGridData::getDataProperty(int property, void **_pvData)
{
    if (property == NUM_X)
    {
        ((int *) *_pvData)[0] = getNumX();
    }
    else if (property == NUM_Y)
    {
        ((int *) *_pvData)[0] = getNumY();
    }
    else if (property == NUM_Z)
    {
        ((int *) *_pvData)[0] = getNumZ();
    }
    else if (property == X_DIMENSIONS)
    {
        *_pvData = getXDimensions();
    }
    else if (property == Y_DIMENSIONS)
    {
        *_pvData = getYDimensions();
    }
    else if (property == X_COORDINATES)
    {
        *_pvData = getDataX();
    }
    else if (property == Y_COORDINATES)
    {
        *_pvData = getDataY();
    }
    else if (property == Z_COORDINATES)
    {
        *_pvData = getDataZ();
    }
    else if (property == Z_COORDINATES_SHIFT)
    {
        ((double *) *_pvData)[0] = getZCoordinatesShift();
    }
    else
    {
        NgonData::getDataProperty(property, _pvData);
    }

}
Esempio n. 4
0
int GridSize<QC_3D>::getNumberOfNodes () const {
  return getNumX() * getNumY() * getNumZ();
}
 int getNumX() const { return getNumZ() ? voxelGrid[0].cols() : 0; };
 int getNumY() const { return getNumZ() ? voxelGrid[0].rows() : 0; };
Esempio n. 7
0
//===============================================================================
ZonePtr Insert2Faces ( ZonePtr pZone2BCut, FacePtr *ppANewFace )
{
	int		numC;			// index to walk the cut_edge data structure
	int		nF;
//	int		nErr;
	ZonePtr	pLEFT_Zone;		// newly created zone; should it be an argument??
	FacePtr	pNewRightFace, pNewLeftFace;	// to be created
	SidePtr	pS,		// to loop over sides of a Face
    pNewS;	// created for each new Face
	
	pLEFT_Zone = allocateZone ( getNumZ() );
	
	NEWSortFaces ( pZone2BCut );				// sort all faces into right and left faces

	pNewRightFace = allocateFace ( getNumF() );			// create the new right face
	pRightFace[num_right_faces] = pNewRightFace;// and add it to the right face list
  pNewRightFace->FType = INTERIOR_FACE;
	num_right_faces = num_right_faces + 1;
				
	pNewLeftFace  = allocateFace ( getNumF() );			// create the new left face
	pLeftFace[num_left_faces] = pNewLeftFace;	// and add it to the left face list
  pNewLeftFace->FType = INTERIOR_FACE;
	num_left_faces = num_left_faces + 1;
		
	for ( numC = 0; numC < num_cuts; numC++ )	// create the two new Sides for each "cut"
	{	//----- first create the top left side and fill its pointers
		pNewS = allocateSide ( getNumS() );
		pNewS->pFace  = pNewLeftFace;
		pNewS->pNode1 = cut_edge[numC].pEndNode;
		pNewS->pNode2 = cut_edge[numC].pStartNode;
		pNewS->pEdge  = cut_edge[numC].pEdge2CutFace;
		AddSideToNodesSideList    (pNewS, pNewS->pNode1);
		AddSideToNodesSideList    (pNewS, pNewS->pNode2);
		InsertSideInEdgesSideList (pNewS, pNewS->pEdge );
		cut_edge[numC].pLeft_top_side  = pNewS;
		
		//----- next create the top right side and fill its pointers
		pNewS = allocateSide ( getNumS() );
		pNewS->pFace  = pNewRightFace;
		pNewS->pNode1 = cut_edge[numC].pStartNode;
		pNewS->pNode2 = cut_edge[numC].pEndNode;
		pNewS->pEdge  = cut_edge[numC].pEdge2CutFace;
		AddSideToNodesSideList    (pNewS, pNewS->pNode1);
		AddSideToNodesSideList    (pNewS, pNewS->pNode2);
		InsertSideInEdgesSideList (pNewS, pNewS->pEdge);
		cut_edge[numC].pRight_top_side  = pNewS;
		
		//---------- now do pTopSide and pOppositeSide linkages starting from left to right
		cut_edge[numC].pLeft_base_side->pTopSide		= cut_edge[numC].pLeft_top_side;
		cut_edge[numC].pLeft_top_side->pTopSide			= cut_edge[numC].pLeft_base_side;
		cut_edge[numC].pLeft_top_side->pOppositeSide	= cut_edge[numC].pRight_top_side;
		cut_edge[numC].pRight_top_side->pOppositeSide	= cut_edge[numC].pLeft_top_side;
		cut_edge[numC].pRight_top_side->pTopSide		= cut_edge[numC].pRight_base_side;
		cut_edge[numC].pRight_base_side->pTopSide		= cut_edge[numC].pRight_top_side;
	}
	
	//-------------------- set right and left linkages of all newly created sides
	for ( numC = 0; numC < num_cuts; numC++ )
	{
		if ( numC == 0 )
		{	cut_edge[0].pLeft_top_side->pLeftSide   = cut_edge[num_cuts-1].pLeft_top_side;
			cut_edge[0].pRight_top_side->pRightSide = cut_edge[num_cuts-1].pRight_top_side;
		}
		else
		{	cut_edge[numC].pLeft_top_side->pLeftSide   = cut_edge[numC-1].pLeft_top_side;
			cut_edge[numC].pRight_top_side->pRightSide = cut_edge[numC-1].pRight_top_side;
		}
		if (numC == num_cuts-1 )
		{	cut_edge[numC].pLeft_top_side->pRightSide  = cut_edge[0].pLeft_top_side;
			cut_edge[numC].pRight_top_side->pLeftSide  = cut_edge[0].pRight_top_side;
		}
		else
		{	cut_edge[numC].pLeft_top_side->pRightSide  = cut_edge[numC+1].pLeft_top_side;
			cut_edge[numC].pRight_top_side->pLeftSide  = cut_edge[numC+1].pRight_top_side;
		}
	}
	
	//----- create CCW ordered Side lists for both new Faces; only works AFTER L&R pointers are set
	MakeAFacesSideList ( pNewRightFace, cut_edge[0].pRight_top_side);
	MakeAFacesSideList ( pNewLeftFace , cut_edge[0].pLeft_top_side );
	
	//----------------------------------- create the CCW ordered Node lists both new Faces
	MakeAFacesNodeListFromSideList ( pNewRightFace);
	MakeAFacesNodeListFromSideList ( pNewLeftFace);

	//nErr = CheckFaceInfo ( pNewRightFace, "I2F, after creating Node list for pNewRightFace.\n" );
	//nErr = CheckFaceInfo ( pNewLeftFace , "I2F, after creating Node list for pNewLeftFace.\n"  );

	ClearZonesFaceList ( pZone2BCut );	ClearZonesSideList ( pZone2BCut );
	ClearZonesFaceList ( pLEFT_Zone );	ClearZonesSideList ( pLEFT_Zone );
	
	for ( nF = 0; nF < num_right_faces; nF++ ) //----- Assign Faces and their Sides to Zone2BCut
	{										   //	   AND Sides to their Faces.
		pRightFace[nF]->pZone = pZone2BCut;
		AddFaceToZonesFaceList (pRightFace[nF], pZone2BCut );
		pS = pRightFace[nF]->p1stSide;
		while ( pS != NULL ) {
			pS->pZone = pZone2BCut;
			pS->pFace = pRightFace[nF];
			AddSideToZonesSideList ( pS, pZone2BCut );
			pS = pS->pFsNextS;							// we follow the FACE'S side list
		}
	}
//	CalcFaceCentroidFromNodes (pNewRightFace);		// Update Face and Zone centroids
//	CalcZoneCentroidFromFaces (pZone2BCut   );
	
	for ( nF = 0; nF < num_left_faces; nF++ ) //----- assign faces and their sides to LEFT_Zone
	{
		pLeftFace[nF]->pZone = pLEFT_Zone;
		AddFaceToZonesFaceList (pLeftFace[nF], pLEFT_Zone );
		pS = pLeftFace[nF]->p1stSide;
		while ( pS != NULL ) {
			pS->pZone = pLEFT_Zone;
			pS->pFace = pLeftFace[nF];
			AddSideToZonesSideList ( pS, pLEFT_Zone );
			pS = pS->pFsNextS;							// we follow the FACE'S side list
		}
	}
//	CalcFaceCentroidFromNodes (pNewLeftFace);		// Update Face and Zone centroids
//	CalcZoneCentroidFromFaces (pLEFT_Zone  );
	
	*ppANewFace = pNewLeftFace;
	return ( pLEFT_Zone );
} // ----- END of Insert2Faces