void ParticleBSPTree::build(Particles *core) { _tree.clear(); if(core == NULL) { FWARNING(("ParticleBSP::build: no core!!\n")); return; } const GeoPositionsPtr pos = core->getPositions(); if(pos == NullFC) return; const MFInt32 *indices = core->getMFIndices(); // 1. create list for particles std::vector<Int32> order; order.reserve(pos->getSize()); for(UInt32 i = 0; i < pos->getSize(); ++i ) { if(indices->size() == pos->getSize()) { order.push_back((*indices)[i]); } else { order.push_back(i); } } // reserve mem for tree _tree.resize(osgnextpower2(order.size()) * 2); // 2. recursively build the tree UInt32 nnodes = doBuild(order.begin(), order.end(), 1, pos); // 3. remove the unneeded elements from the end if(nnodes < _tree.size()) _tree.erase( _tree.begin() + nnodes, _tree.end()); // done }
void FaceSpatializeIndexed<BasicTraits>::CategoryRaw::addData (OpenSGFaceBase<OpenSGTraits>* node, const FaceIterator& face) { GeoPositions3f::StoredFieldType* p = m_coord->getFieldPtr(); GeoNormals3f::StoredFieldType* n = m_normal->getFieldPtr(); //GeoIndicesUI32::StoredFieldType* i = m_index->getFieldPtr(); // find offset of positions and normals in the new geometry u32 i, k; m_offsetIt = m_offset.find(face.getGeometry()); if (m_offsetIt == m_offset.end()) { // insert new offsets entry into map HashMapPair offsetPair = m_offset.insert(HashMap::value_type(face.getGeometry(), quad())); m_offsetIt = offsetPair.first; m_offsetIt->second.position = m_coord->size(); GeoPositionsPtr faceP = m_original.getPositions(); addRefCP(faceP); for (k=0; k<faceP->getSize(); ++k) { p->addValue(faceP->getValue(k)); } if (m_hasNormal) { m_offsetIt->second.normal = m_normal->size(); GeoNormalsPtr faceN = m_original.getNormals(); addRefCP(faceN); for (k=0; k<faceN->getSize(); ++k) { n->addValue(faceN->getValue(k)); } subRefCP(faceN); } subRefCP(faceP); } // insert indices if (face.getLength() == 3) { for (k=0; k<3; ++k) { m_index->insertValue(face.getPositionIndex(k)+m_offsetIt->second.position, m_quadOffset++); i = 1; if (m_hasNormal) { m_index->insertValue(face.getNormalIndex(k)+m_offsetIt->second.normal, m_quadOffset++); ++i; } for (; i<m_indexStride; ++i) { m_index->insertValue(0, m_quadOffset++); } } } else { for (k=0; k<4; ++k) { m_index->addValue(face.getPositionIndex(k)+m_offsetIt->second.position); i = 1; if (m_hasNormal) { m_index->addValue(face.getNormalIndex(k)+m_offsetIt->second.normal); ++i; } for (; i<m_indexStride; ++i) { m_index->addValue(0); } } } }
// redraw the window void display( void ) { // create the matrix Matrix m; Real32 t = glutGet(GLUT_ELAPSED_TIME ); m.setTransform(Quaternion( Vec3f(0,1,0), t / 1000.f)); // set the transform's matrix beginEditCP(trans, Transform::MatrixFieldMask); { trans->setMatrix(m); } endEditCP (trans, Transform::MatrixFieldMask); /* Manipulate the geometry. The OpenSG geometry structure is pretty flexible. The disadvantage of all this flexibility is that it can be hard to write generic tools, as pretty much all the used types can be one of a number of variants. To simplify that, every kind of GeoProperty has a generic type, e.g. the generic type for positions is Pnt3f, for colors it's Color3f. No matter the internal data representation looks like, all GeoProperties have the generic interface. As does the abstract parent class of every kind of property. Thus it's possible to access the data of an arbitrary geometry using the generic interface. */ // note that this is the abstract parent class, it doesn't have a specific // type GeoPositionsPtr pos = geo->getPositions(); beginEditCP(pos); for(UInt32 i = 0; i < pos->getSize(); i++) { Pnt3f p; pos->getValue(p, i); p[0] += osgsin(t / 300) * p[1] / 100; p[1] += osgsin(t / 300) * p[2] / 100; p[2] += osgsin(t / 300) * p[0] / 100; pos->setValue(p, i); } endEditCP (pos); // right now the geometry doesn't notice changes to the properties, it has // to be notified explicitly beginEditCP(geo, Geometry::PositionsFieldMask); endEditCP (geo, Geometry::PositionsFieldMask); mgr->redraw(); }
void FaceSpatialize<BasicTraits>::CategoryRaw::addData (OpenSGFaceBase<OpenSGTraits>* node, const FaceIterator& face) { GeoPositions3f::StoredFieldType* p = m_coord->getFieldPtr(); GeoNormals3f::StoredFieldType* n = m_normal->getFieldPtr(); //GeoIndicesUI32::StoredFieldType* i = m_index->getFieldPtr(); GeoPositionsPtr faceP = node->getPositions(); addRefCP(faceP); u32 k; for (k=0; k<faceP->getSize(); ++k) { p->addValue(faceP->getValue(k)); if (face.getLength()==3) { m_index->insertValue(p->size()-1, m_quadOffset++); } else { m_index->addValue(p->size()-1); } } if (!m_hasNormal) { #if 1 Vec3f p0(faceP->getValue(0)); Vec3f p1(faceP->getValue(1)); Vec3f p2(faceP->getValue(2)); p2 -= p1; p0 -= p1; if (m_ccw) { p0.crossThis(p2); p0.normalize(); n->addValue(p0); } else { p2.crossThis(p0); p2.normalize(); n->addValue(p2); } #endif } else { // per-vertex normals or per-face normals GeoNormalsPtr faceN = node->getNormals(); addRefCP(faceN); for (k=0; k<faceN->getSize(); ++k) { n->addValue(faceN->getValue(k)); } subRefCP(faceN); } subRefCP(faceP); }
Action::ResultE OOCOSGFeeder::enter(NodePtr& node) { GeometryPtr geo = GeometryPtr::dcast(node->getCore()); if(geo == NullFC) return Action::Continue; GeoPositionsPtr pos = geo->getPositions(); UInt32 pntindexbase; if(_poss.find(pos) != _poss.end()) { pntindexbase = _poss[pos]; pos = NullFC; } else { pntindexbase = _pntindexbase; _poss[pos] = _pntindexbase; _pntindexbase += pos->getSize(); } UInt32 matind = MaterialPool::addMaterial(geo->getMaterial()); if(pos != NullFC) { if(_pfunc != NULL) { Pnt3f p; UInt32 s = pos->getSize(); for(UInt32 i = 0; i < s; ++i) { if(_npts != 0) { ++_pntprog; Real32 prog = _pntprog / (Real32)_npts; if(prog > _nextpntprog) { PLOG << _nextpntprog * 100 << "%.."; _nextpntprog += 0.1; } } pos->getValue(p, i); _pfunc(_rec, p); } } } if(_tfunc != NULL) { TriangleIterator it, end = geo->endTriangles(); for(it = geo->beginTriangles(); it != end; ++it) { if(_ntris != 0) { ++_triprog; Real32 prog = _triprog / (Real32)_ntris; if(prog > _nexttriprog) { PLOG << _nexttriprog * 100 << "%.."; _nexttriprog += 0.1; } } _tfunc(_rec, it.getPositionIndex(0) + pntindexbase, it.getPositionIndex(1) + pntindexbase, it.getPositionIndex(2) + pntindexbase, matind); } } return Action::Continue; }