GLC_BoundingBox GLC_StructOccurence::boundingBox() const { GLC_BoundingBox boundingBox; if (NULL != m_pWorldHandle) { if (has3DViewInstance()) { Q_ASSERT(m_pWorldHandle->collection()->contains(id())); boundingBox= m_pWorldHandle->collection()->instanceHandle(id())->boundingBox(); } else { if (hasChild()) { QList<GLC_StructOccurence*> childrenList= children(); const int size= childrenList.size(); for (int i= 0; i < size; ++i) { boundingBox.combine(childrenList.at(i)->boundingBox()); } } } } return boundingBox; }
// Return the 3DRep bounding Box GLC_BoundingBox GLC_3DRep::boundingBox() const { GLC_BoundingBox resultBox; const int size= m_pGeomList->size(); for (int i= 0; i < size; ++i) { resultBox.combine(m_pGeomList->at(i)->boundingBox()); } return resultBox; }
void GLC_Viewport::reframe(const GLC_BoundingBox& box) { Q_ASSERT(!box.isEmpty()); // Center view on the BoundingBox const GLC_Vector3d deltaVector(box.center() - m_pViewCam->target()); m_pViewCam->translate(deltaVector); double cameraCover= box.boundingSphereRadius() * 2.0; // Compute Camera distance const double distance = cameraCover / m_ViewTangent; // Update Camera position m_pViewCam->setDistEyeTarget(distance); }
void GLC_OctreeNode::addInstance(GLC_3DViewInstance* pInstance, int depth) { m_Empty= false; const GLC_BoundingBox instanceBox= pInstance->boundingBox(); // Check if the instance's bounding box intersect this node bounding box if (!instanceBox.isEmpty() && intersect(instanceBox)) { if (0 == depth) { m_3DViewInstanceSet.insert(pInstance); } else { if (m_Children.isEmpty()) { // Create children addChildren(); } QVector<bool> childIntersect(8); bool allIntersect= true; bool currentIntersect= false; for (int i= 0; i < 8; ++i) { currentIntersect= m_Children.at(i)->intersect(instanceBox); allIntersect= allIntersect && currentIntersect; childIntersect[i]= currentIntersect; } if (allIntersect) { m_3DViewInstanceSet.insert(pInstance); } else { for (int i= 0; i < 8; ++i) { if (childIntersect[i]) { m_Children[i]->addInstance(pInstance, depth - 1); } } } } } }
GLC_BoundingBox GLC_3DViewCollection::boundingBox(bool allObject) { GLC_BoundingBox boundingBox; // Check if the bounding box have to be updated if (!m_3DViewInstanceHash.isEmpty()) { ViewInstancesHash::iterator iEntry= m_3DViewInstanceHash.begin(); while (iEntry != m_3DViewInstanceHash.constEnd()) { if(allObject || iEntry.value().isVisible() == m_IsInShowSate) { // Combine Collection BoundingBox with element Bounding Box boundingBox.combine(iEntry.value().boundingBox()); } ++iEntry; } } return boundingBox; }
GLC_Camera GLC_Viewport::reframedCamera(const GLC_BoundingBox &box, double coverFactor) const { Q_ASSERT(!box.isEmpty()); GLC_Camera subject(*m_pViewCam); // Center view on the BoundingBox const GLC_Vector3d deltaVector(box.center() - m_pViewCam->target()); subject.translate(deltaVector); if (coverFactor > 0.0) { double cameraCover= box.boundingSphereRadius() * coverFactor; // Compute Camera distance const double distance = cameraCover / m_ViewTangent; // Update Camera position subject.setDistEyeTarget(distance); } return subject; }
GLC_3DViewInstance GLC_Factory::createBox(const GLC_BoundingBox& boundingBox) const { const double lx= boundingBox.upperCorner().x() - boundingBox.lowerCorner().x(); const double ly= boundingBox.upperCorner().y() - boundingBox.lowerCorner().y(); const double lz= boundingBox.upperCorner().z() - boundingBox.lowerCorner().z(); GLC_Box* pBox= new GLC_Box(lx, ly, lz); GLC_3DViewInstance newBox(pBox); newBox.translate(boundingBox.center().x(), boundingBox.center().y() , boundingBox.center().z()); return newBox; }
void GLC_Viewport::setDistMinAndMax(const GLC_BoundingBox& bBox) { if(!bBox.isEmpty()) { // The scene is not empty GLC_Matrix4x4 matComp(m_pViewCam->modelViewMatrix()); // The bounding Box in Camera coordinate GLC_BoundingBox boundingBox(bBox); boundingBox.transform(matComp); // Increase size of the bounding box const double increaseFactor= 1.1; // Convert box distance in sphere distance const double center= fabs(boundingBox.center().z()); const double radius= boundingBox.boundingSphereRadius(); const double min= center - radius * increaseFactor; const double max= center + radius * increaseFactor; GLC_Point3d camEye(m_pViewCam->eye()); camEye= matComp * camEye; if (min > 0.0) { // Outside bounding Sphere m_dDistanceMini= min; m_DistanceMax= max; //qDebug() << "distmin" << m_dCamDistMin; //qDebug() << "distmax" << m_dCamDistMax; } else { // Inside bounding Sphere m_dDistanceMini= qMin(0.01 * radius, m_pViewCam->distEyeTarget() / 4.0); m_DistanceMax= max; //qDebug() << "inside distmin" << m_dCamDistMin; //qDebug() << "inside distmax" << m_dCamDistMax; } } else { // The scene is empty m_dDistanceMini= m_pViewCam->distEyeTarget() / 2.0; m_DistanceMax= m_pViewCam->distEyeTarget(); } // Update OpenGL projection matrix updateProjectionMat(); }