int FullSegmentInfo(ANT_DESK info, int segment, float mas, float heigh, float *pMas, int *pNum, ANT_INFO *antrop) { int i = 0; float persent, norm; *antrop = SegmentInfo(mas, heigh, segment, info); if (fabs(antrop->mass) < 0.000001) return 0; if (segment >= UNI_SEGMENTS_NUM) segment -= TOTAL_SEGMENTS_NUM - UNI_SEGMENTS_NUM; rewind(info.model); ShiftDown(info.model, segment, i); while (fgetc(info.model) != ';'); if (!fscanf(info.model, "%d", pNum)) return 0; for (i = 0; i < *pNum; i++) { if (fscanf(info.model,";%f;%f;%f;%f", pMas + 3*i, pMas + 3*i + 1, pMas + 3*i + 2, &persent) != 4) return 0; norm = sqrt(pMas[3*i]*pMas[3*i] + pMas[3*i + 1]*pMas[3*i + 1] + pMas[3*i + 2]*pMas[3*i + 2]); norm = (persent * antrop->length) / (norm * 100); // norm = (antrop->length) / (norm * 100); pMas[3*i] *= norm; pMas[3*i + 1] *= norm; pMas[3*i + 2] *= norm; } return 1; }
void SegmentInfos::read(Directory* directory) { //Func - Reads segments file that resides in directory. //Pre - directory contains a valid reference //Post - The segments file has been read and for each segment found // a SegmentsInfo intance has been created and stored. //Open an IndexInput to the segments file and check if valid IndexInput* input = directory->openInput(QLatin1String("segments")); if (input) { try { int32_t format = input->readInt(); // file contains explicit format info if (format < 0) { // check that it is a format we can understand if (format < FORMAT) { TCHAR err[30]; _sntprintf(err, 30, _T("Unknown format version: %d"), format); _CLTHROWT(CL_ERR_Runtime, err); } // read version version = input->readLong(); // read counter counter = input->readInt(); } else { // file is in old format without explicit format info counter = format; } //Temporary variable for storing the name of the segment char aname[CL_MAX_PATH] = { 0 }; TCHAR tname[CL_MAX_PATH] = { 0 }; //read segmentInfos for (int32_t i = input->readInt(); i > 0; --i) { // read the name of the segment input->readString(tname, CL_MAX_PATH); STRCPY_TtoA(aname, tname, CL_MAX_PATH); //Instantiate a new SegmentInfo Instance SegmentInfo* si = _CLNEW SegmentInfo(QLatin1String(aname), input->readInt(), directory); //Condition check to see if si points to an instance CND_CONDITION(si != NULL, "Memory allocation for si failed") ; //store SegmentInfo si infos.push_back(si); } if (format >= 0) { // in old format the version number may be at the end of the file if (input->getFilePointer() >= input->length()) { // old file format without version number version = Misc::currentTimeMillis(); } else { // read version version = input->readLong(); } } } _CLFINALLY ( //destroy the inputStream input. The destructor of IndexInput will //also close the Inputstream input _CLDELETE(input); ); }