ZSwcTree* ZSwcGenerator::createSurfaceSwc( const ZObject3dScan &obj, int sparseLevel) { size_t volume = obj.getBoundBox().getVolume(); int intv = 0; if (volume > MAX_INT32) { intv = iround(Cube_Root((double) volume / MAX_INT32)); } ZStack *stack = NULL; std::cout << "Creating object mask ..." << "ds: " << intv << std::endl; if (intv > 0) { ZObject3dScan obj2 = obj; obj2.downsampleMax(intv, intv, intv); stack = obj2.toStackObject(); } else { stack = obj.toStackObject(); } ZSwcTree *tree = NULL; if (stack != NULL) { tree = createSurfaceSwc(*stack, sparseLevel); tree->setColor(obj.getColor()); tree->rescale(intv + 1, intv + 1, intv + 1); delete stack; } return tree; }
Apo_Node* Read_Apo_File(char *file_path, int *napo) { FILE *fp = GUARDED_FOPEN(file_path, "r"); String_Workspace *sw = New_String_Workspace(); int n = 0; while (Read_Line(fp, sw) != NULL) { n++; } Apo_Node *apos = (Apo_Node*)malloc(sizeof(Apo_Node)*n); *napo = 0; fseek(fp, 0, SEEK_SET); char *line = NULL; while ((line = Read_Line(fp, sw)) != NULL) { apos[*napo].no = atoi(line); char *head1 = strsplit(line, ',', 2); if (head1 == NULL) { continue; } char *head2 = strsplit(head1, ',', 1); if (head2 == NULL) { continue; } char *token = strsplit(head2, ',', 1); if (token != NULL) { strcpy(apos[*napo].name, head1); strcpy(apos[*napo].comment, head2); apos[*napo].z = atof(token); } else { continue; } token = strsplit(token, ',', 1); if (token != NULL) { apos[*napo].x = atof(token); } else { continue; } token = strsplit(token, ',', 1); if (token != NULL) { apos[*napo].y = atof(token); } else { continue; } token = strsplit(token, ',', 1); if (token != NULL) { apos[*napo].maxintensity = atof(token); } else { continue; } token = strsplit(token, ',', 1); if (token != NULL) { apos[*napo].intensity = atof(token); } else { continue; } token = strsplit(token, ',', 1); if (token != NULL) { apos[*napo].sdev = atof(token); } else { continue; } token = strsplit(token, ',', 1); if (token != NULL) { apos[*napo].volsize = atof(token); } else { continue; } token = strsplit(token, ',', 1); if (token != NULL) { apos[*napo].mass = atof(token); } else { continue; } token = strsplit(token, ',', 1); token = strsplit(token, ',', 1); token = strsplit(token, ',', 1); token = strsplit(token, ',', 1); if (token == NULL) { apos[*napo].r = Cube_Root(0.75 / TZ_PI * apos[*napo].volsize); ++(*napo); continue; } head1 = strsplit(token, ',', 1); if (head1 == NULL) { continue; } head2 = strsplit(head1, ',', 1); if (head2 == NULL) continue; else { strcpy(apos[*napo].colorr, token); strcpy(apos[*napo].colorg, head1); strcpy(apos[*napo].colorb, head2); } // token = strsplit(token, ',', 1); // if (token != NULL) { // strcpy(apos[*napo].colorb, token); // } else { // continue; // } apos[*napo].r = Cube_Root(0.75 / TZ_PI * apos[*napo].volsize); ++(*napo); } Kill_String_Workspace(sw); fclose(fp); return apos; }