#include "stdlib.h" #include "math.h" #include "assert.h" #include #include #include "pointcloud.h" using namespace std; using std::cout; using std::endl; using std::string; int main(int argc, char *argv[]) { if(argc != 2){ fprintf(stderr, "ho_ptMaker "); exit(1); } char *dataFile = argv[1]; int arg1len = (int)strlen(dataFile); char *ptFile = (char*)malloc((arg1len+5)*sizeof(char)); strcpy(ptFile,dataFile); strcat(ptFile,".ptc"); ////////////////////////////////////////////////////////////////////////// fstream myFile; myFile.open( dataFile ); int nvars = 1; char *valueType = (char*)malloc(256); myFile.getline(valueType,256); char *vartypes[1] = {valueType}; char *valueName =(char*)malloc(256); myFile.getline(valueName,256); char *varnames[1] = {valueName}; float format[3] = {320,320,1}; //transform default float w2e[16] = { 1,0,0,0, 0,1,0,0, 0,0,-1,0, 0,0,0,1 }; //tmp camera float w2n[16]= { 1.78,0,0,0, 0,3.17,0,0, 0,0,-1,-1, 0,0,0-.1,0 }; float point[3]; float normal[3]; float radius = 1; //float myData[1]; float *data=(float*)malloc(1*sizeof(float)+1); float *data3=(float*)malloc(3*sizeof(float)+1); char buff[100]; myFile.getline(buff,101); int xRez = atoi(buff); myFile.getline(buff,101); int yRez = atoi(buff); myFile.getline(buff,101); int zRez = atoi(buff); myFile.getline(buff,101); float bbXmin = atof(buff); myFile.getline(buff,101); float bbYmin = atof(buff); myFile.getline(buff,101); float bbZmin = atof(buff); myFile.getline(buff,101); float bbXmax = atof(buff); myFile.getline(buff,101); float bbYmax = atof(buff); myFile.getline(buff,101); float bbZmax = atof(buff); float tmpX = bbXmin; float tmpY = bbYmin; float tmpZ = bbZmin; float increseX = (bbXmax - bbXmin)/xRez; float increseY = (bbYmax - bbYmin)/yRez; float increseZ = (bbZmax - bbZmin)/zRez; PtcPointCloud myPt = PtcCreatePointCloudFile( ptFile,nvars,vartypes,varnames,w2e, w2n, format); for(int i = 0 ; i < xRez ; i++){ for(int j = 0 ; j < yRez ; j++){ for(int k = 0 ; k < zRez ; k++){ int oder = 0; if(oder == 1){ //for Maya point[0] = tmpX+increseX*i; point[1] = tmpY+increseY*j; point[2] = tmpZ+increseZ*k; }else{ //for Max point[0] = tmpX+increseX*i; point[2] = tmpY+increseY*j; point[1] = tmpZ+increseZ*k; } char buff[100]; myFile.getline(buff,101); if(!strcmp(valueType,"vector")){ printf("not supported vector yet"); exit(1); char *pch; pch = strtok (buff," "); int n = 0; while (pch != NULL){//printf(pch);exit(1); data[n] = atof(pch); pch = strtok(NULL, " "); n+=1; } if(data[0] > 0.0001 || data[1] > 0.0001 || data[2] > 0.0001){ PtcWriteDataPoint(myPt, point, data3, radius, data3); } }else{ *data = atof(buff); if(*data > 0.0001){ PtcWriteDataPoint(myPt, point, normal, radius, data); } } } } cout << (float)i/xRez*100; printf(" percent...\n"); } myFile.close(); printf("fileClosed"); PtcFinishPointCloudFile(myPt); printf("output file : "); printf(ptFile); free(ptFile);free(valueType);free(valueName); free(data);free(data3); return 0; /* success */ }