boost::shared_ptr<PhysicsMesh> ParticlePhysics::createConvexMesh(const char *filename, IStorm3D_Model_Object *object) { boost::shared_ptr<PhysicsMesh> mesh(new PhysicsMesh()); IStorm3D_Mesh *stormMesh = object->GetMesh(); int vertexAmount = stormMesh->GetVertexCount(); const Storm3D_Vertex *buffer = stormMesh->GetVertexBufferReadOnly(); VC3 minValues(10000.f, 10000.f, 10000.f); VC3 maxValues(-10000.f, -10000.f, -10000.f); for(int i = 0; i < vertexAmount; ++i) { VC3 pos = buffer[i].position; minValues.x = std::min(minValues.x, pos.x); minValues.y = std::min(minValues.y, pos.y); minValues.z = std::min(minValues.z, pos.z); maxValues.x = std::max(maxValues.x, pos.x); maxValues.y = std::max(maxValues.y, pos.y); maxValues.z = std::max(maxValues.z, pos.z); } VC3 size = maxValues - minValues; if(size.x < MIN_BOX_SIZE) { float diff = (MIN_BOX_SIZE - size.x) * 0.5f; maxValues.x += diff; minValues.x -= diff; } if(size.y < MIN_BOX_SIZE) { float diff = (MIN_BOX_SIZE - size.y) * 0.5f; maxValues.y += diff; minValues.y -= diff; } if(size.z < MIN_BOX_SIZE) { float diff = (MIN_BOX_SIZE - size.z) * 0.5f; maxValues.z += diff; minValues.z -= diff; } mesh->size = (maxValues - minValues) * 0.5f; mesh->localPosition = minValues + mesh->size; mesh->localPosition.y -= mesh->size.y; mesh->volume = mesh->size.x * mesh->size.y * mesh->size.z * 2.f; return mesh; }
void iAIDA::AIDA_HBookStore::HBook::getTupleParameters( const int& id, std::string& title, std::vector<std::string>& columnNames, std::vector<std::pair<float,float> >& columnMinAndMax) { const int tagLength = iAIDA::AIDA_HBookStore::HBook::MAXTAGLEN; const int tagArrayLength = iAIDA::AIDA_HBookStore::HBook::MAXVAR*tagLength; const int titleArrayLength = iAIDA::AIDA_HBookStore::HBook::MAXLEN; const int minMaxArrayLength = iAIDA::AIDA_HBookStore::HBook::MAXVAR; columnNames.clear(); columnMinAndMax.clear(); char* titleArray = new char[titleArrayLength]; char* tagArray = new char[tagArrayLength]; for (int i = 0; i < titleArrayLength; ++i) titleArray[i] = ' '; for (int i = 0; i < tagArrayLength; ++i) tagArray[i] = ' '; std::vector< float > maxValues( minMaxArrayLength, 0.0 ); std::vector< float > minValues( minMaxArrayLength, 0.0 ); int tid = id; int ncol = minMaxArrayLength; hgiven_(&tid, titleArray, &ncol, tagArray, &( minValues[0] ), &( maxValues[0] ), titleArrayLength, tagLength ); columnNames.clear(); if ( ncol > 0 ) columnNames.reserve( ncol ); for ( int i = 0; i < ncol; ++i ) { std::string sTagName = &( tagArray[ i*MAXTAGLEN ] ); std::istringstream is( sTagName.substr( 0, MAXTAGLEN ).c_str() ); std::string tagName; is >> tagName >> std::ws; columnNames.push_back( tagName ); } title = std::string( titleArray ); int nwhiteSpaces = 0; const int maxWhiteSpaces = 10; // patch to get rid of funny characters !!! for ( unsigned int i = 0; i < title.size(); ++i ) { char c = title[i]; if ( c == '\n' || c == '\0' || c == '\r' || c == '\t' ) { title = title.substr( 0, i ); break; } if ( c == ' ' || c == '\t' ) ++nwhiteSpaces; if ( nwhiteSpaces == maxWhiteSpaces ) { title = title.substr( 0, i ); break; } } int last = title.length() - 1; if (last < 0) return; // LM: add check last >=0 while (! isgraph(title[last]) && last>=0 ) title.erase(last--,1); delete [] titleArray; delete [] tagArray; for (int i = 0; i < ncol; ++i) columnMinAndMax.push_back(std::make_pair(minValues[i],maxValues[i])); }