/** * SPHデータのロード * @param filename ファイルパス * @retval true 成功 * @retval false 失敗 */ bool SPHLoader::Load(const char* filename) { Clear(); m_volume = BufferVolumeData::CreateInstance(); SimpleSPH sph; const float* buf = sph.Load(filename); if (!buf) { fprintf(stderr,"Failed to load SPH volume: %s\n", filename); return false; } const int w = sph.GetDim(0); const int h = sph.GetDim(1); const int d = sph.GetDim(2); const int c = sph.GetComponent(); m_volume->Create(w, h, d, c); FloatBuffer* buffer = m_volume->Buffer(); const int fnum = w * h * d * c; memcpy(buffer->GetBuffer(), buf, fnum * sizeof(float)); delete [] buf; m_origin[0] = sph.GetOrigin(0); m_origin[1] = sph.GetOrigin(1); m_origin[2] = sph.GetOrigin(2); m_pitch[0] = sph.GetPitch(0); m_pitch[1] = sph.GetPitch(1); m_pitch[2] = sph.GetPitch(2); m_time = sph.GetTime(); m_step = sph.GetStep(); return true; }
/** * STLデータのロード * @param filename ファイルパス * @retval true 成功 * @retval false 失敗 */ bool STLLoader::Load(const char* filename){ Clear(); SimpleSTLB obj; bool r = obj.Load(filename); mesh.Create(obj.GetVertexNum(), obj.GetIndexNum()); Vec3Buffer* pos = mesh.Position(); Vec3Buffer* normal = mesh.Normal(); FloatBuffer* mat = mesh.Material(); UintBuffer* index = mesh.Index(); Vec2Buffer* texcoord = mesh.Texcoord(); memcpy(pos->GetBuffer(), obj.GetPositionBuffer(), sizeof(float) * 3 * pos->GetNum()); normal->Create(obj.GetVertexNum()); memcpy(normal->GetBuffer(), obj.GetNormalBuffer(), sizeof(float) * 3 * normal->GetNum()); mat->Create(obj.GetVertexNum()); memset(mat->GetBuffer(), 0, sizeof(float) * mat->GetNum()); index->Create(obj.GetIndexNum()); memcpy(index->GetBuffer(), obj.GetIndex(), sizeof(unsigned int) * index->GetNum()); printf("%d\n", pos->GetNum() ); printf("%d\n", normal->GetNum() ); printf("%d\n", mat->GetNum() ); printf("%d\n", index->GetNum() ); return r; }
/** * マテリアル設定 * @param i 対象index * @param matID マテリアルID */ void PDBLoader::SetMaterial(int i, float matID) { FloatBuffer* mat = ball.Material(); if (i < 0 || i >= mat->GetNum()) { return; } mat->GetBuffer()[i] = matID; }
/** * BCMデータのロード * @param filename ファイルパス * @param generateBond 線primitiveとの接点作成 * @retval true 成功 * @retval false 失敗 */ bool PDBLoader::Load(const char* filename, bool generateBond){ Clear(); tinypdb::TinyPDB pdb(filename); if (pdb.Parse(/* isBondGenerated = */ generateBond)) { fprintf(stderr,"[PDBLoader] PDB parsing failed: %s \n", filename); return false; } m_atoms = pdb.GetAtoms(); // copy int numAtoms = static_cast<int>(pdb.GetAtoms().size()); { ball.Create(numAtoms); Vec3Buffer* pos = ball.Position(); FloatBuffer* mat = ball.Material(); FloatBuffer* radius = ball.Radius(); printf("[PDBLoader] # of atoms: %ld\n", numAtoms); float* pp = pos->GetBuffer(); for (size_t i = 0; i < numAtoms; i++) { pp[3*i+0] = pdb.GetAtoms()[i].GetX(); pp[3*i+1] = pdb.GetAtoms()[i].GetY(); pp[3*i+2] = pdb.GetAtoms()[i].GetZ(); } // @fixme float* rad = radius->GetBuffer(); for (int i = 0; i < numAtoms; ++i) { rad[i] = 0.25f; } // @todo memset(mat->GetBuffer(), 0, sizeof(float) * mat->GetNum()); } if (generateBond) { // We reprent Bond as line primitives. std::vector<float> bondLines; for (unsigned int i = 0; i < numAtoms; i++) { tinypdb::Atom& atom = pdb.GetAtoms()[i]; for (unsigned int j = 0; j < atom.GetBonds().size(); j++) { const tinypdb::Atom* dst = atom.GetBonds()[j]; if (dst->Visited()) { continue; } bondLines.push_back(atom.GetX()); bondLines.push_back(atom.GetY()); bondLines.push_back(atom.GetZ()); bondLines.push_back(dst->GetX()); bondLines.push_back(dst->GetY()); bondLines.push_back(dst->GetZ()); } atom.SetVisited(true); } size_t numBonds = bondLines.size() / 3 / 2; size_t numBondVertices = numBonds * 2; printf("[PDBLoader] # of bonds: %ld\n", numBonds); stick.Create(numBondVertices, /* index num = */0, /* use vrying radius */false); Vec3Buffer* pos = stick.Position(); FloatBuffer* mat = stick.Material(); //FloatBuffer* radius = stick.Radius(); //UintBuffer* index = stick.Index(); // not used. float* pp = pos->GetBuffer(); for (size_t i = 0; i < numBondVertices; i++) { pp[3*i+0] = bondLines[3*i+0]; pp[3*i+1] = bondLines[3*i+1]; pp[3*i+2] = bondLines[3*i+2]; } // Don't use varying radius. //float* rad = radius->GetBuffer(); //for (int i = 0; i < numBondVertices; ++i) { // rad[i] = 1.0f; //} // @todo memset(mat->GetBuffer(), 0, sizeof(float) * mat->GetNum()); } return true; }