bool TriangleBasic::doesIntersectBox(BoundingBox & bbox) { // prepare the data and call the "triBoxOverlap" worker routine double boxcenter[3]; double boxhalfsize[3]; double triverts[3][3]; Vec3d center_ = bbox.center(); Vec3d halfSides_ = bbox.halfSides(); boxcenter[0] = center_[0]; boxcenter[1] = center_[1]; boxcenter[2] = center_[2]; boxhalfsize[0] = halfSides_[0]; boxhalfsize[1] = halfSides_[1]; boxhalfsize[2] = halfSides_[2]; triverts[0][0] = first_[0]; triverts[0][1] = first_[1]; triverts[0][2] = first_[2]; triverts[1][0] = second_[0]; triverts[1][1] = second_[1]; triverts[1][2] = second_[2]; triverts[2][0] = third_[0]; triverts[2][1] = third_[1]; triverts[2][2] = third_[2]; return triBoxOverlap(boxcenter,boxhalfsize,triverts); }
void BlockBccMeshBuilder::addAnchorByThreshold(ATetrahedronMesh * mesh, unsigned istripe, const Matrix33F & invspace, const Vector3F & center, float threshold, bool isLower, unsigned tri) { unsigned tetMax = mesh->numTetrahedrons() * 4; if(istripe < indexDrifts.size() -1) tetMax = indexDrifts[istripe + 1]; BoundingBox box; Vector3F q; unsigned i = indexDrifts[istripe]; unsigned j; for(;i<tetMax;i+=4) { unsigned * tet = mesh->tetrahedronIndices(i/4); box.reset(); for(j=0; j< 4; j++) box.expandBy(mesh->points()[tet[j]], 1e-3f); q = invspace.transform(box.center() - center); if(isLower) { if(q.x > threshold) continue; } else { if(q.x < threshold) continue; } for(j=0; j< 4; j++) mesh->anchors()[tet[j]] = (1<<24 | tri); } }
static void adjustTextBoundingBox(BoundingBox &textBB, const Camera &camera, float minSize, float maxSize, unsigned int nbLines) { Vec4i viewport = camera.getViewport(); Vec2f textBBMinScr = computeScreenPos(camera.transformMatrix(), viewport, textBB[0]); Vec2f textBBMaxScr = computeScreenPos(camera.transformMatrix(), viewport, textBB[1]); float screenH = (textBBMaxScr[1] - textBBMinScr[1]) / nbLines; Vec3f center = textBB.center(); Vec3f scale = textBB[1] - textBB[0]; float ratio = textBB.width() / textBB.height(); float scaleX = textBB.width(); if (screenH < minSize) { scaleX *= (minSize/screenH); } if (screenH > maxSize) { scaleX *= (maxSize/screenH); } float scaleY = scaleX/ratio; textBB[0][0] = ((textBB[0][0] - center[0]) / scale[0]) * scaleX + center[0]; textBB[0][1] = ((textBB[0][1] - center[1]) / scale[1]) * scaleY + center[1]; textBB[1][0] = ((textBB[1][0] - center[0]) / scale[0]) * scaleX + center[0]; textBB[1][1] = ((textBB[1][1] - center[1]) / scale[1]) * scaleY + center[1]; }
void BoundingSphere::expandBy(const BoundingBox& bb) { if (bb.valid()) { if (valid()) { BoundingBox newbb(bb); for(unsigned int c=0;c<8;++c) { Vec3 v = bb.corner(c)-_center; // get the direction vector from corner v.normalize(); // normalise it. v *= -_radius; // move the vector in the opposite direction distance radius. v += _center; // move to absolute position. newbb.expandBy(v); // add it into the new bounding box. } _center = newbb.center(); _radius = newbb.radius(); } else { _center = bb.center(); _radius = bb.radius(); } } }
void ExampVox::voxelize2(sdb::VectorArray<cvx::Triangle> * tri, const BoundingBox & bbox) { TreeProperty::BuildProfile bf; bf._maxLeafPrims = 64; KdEngine engine; KdNTree<cvx::Triangle, KdNode4 > gtr; engine.buildTree<cvx::Triangle, KdNode4, 4>(>r, tri, bbox, &bf); BoundingBox tb = gtr.getBBox(); const float gz = tb.getLongestDistance() * 1.23f; const Vector3F cent = tb.center(); tb.setMin(cent.x - gz, cent.y - gz, cent.z - gz ); tb.setMax(cent.x + gz, cent.y + gz, cent.z + gz ); ttg::FieldTriangulation msh; msh.fillBox(tb, gz); BDistanceFunction distFunc; distFunc.addTree(>r); distFunc.setDomainDistanceRange(gz * GDT_FAC_ONEOVER8 ); msh.frontAdaptiveBuild<BDistanceFunction>(&distFunc, 3, 4, .3f); msh.triangulateFront(); std::cout.flush(); buildTriangleDrawBuf(msh.numFrontTriangles(), msh.triangleIndices(), msh.numVertices(), msh.triangleVertexP(), msh.triangleVertexN() ); }
static void renderText(NVGcontext *vg, const std::string &text, const tlp::BoundingBox &renderingBox, const tlp::Color &textColor) { vector<string> textVector = splitStringToLines(text); float fontSize = renderingBox.height()/textVector.size(); nvgFontSize(vg, fontSize); nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE); nvgFillColor(vg, nvgRGBA(textColor[0],textColor[1],textColor[2],textColor[3])); for (size_t i = 0 ; i < textVector.size() ; ++i) { BoundingBox rb; rb[0] = Vec3f(renderingBox[0][0], renderingBox[0][1] + i * fontSize); rb[1] = Vec3f(renderingBox[1][0], renderingBox[0][1] + (i+1) * fontSize); nvgText(vg, rb.center()[0], rb.center()[1], textVector[i].c_str(), NULL); } }
BoundingSphere Group::computeBound() const { BoundingSphere bsphere; if (_children.empty()) { return bsphere; } // note, special handling of the case when a child is an Transform, // such that only Transforms which are relative to their parents coordinates frame (i.e this group) // are handled, Transform relative to and absolute reference frame are ignored. BoundingBox bb; bb.init(); NodeList::const_iterator itr; for(itr=_children.begin(); itr!=_children.end(); ++itr) { osg::Node* child = itr->get(); const osg::Transform* transform = child->asTransform(); if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF) { osg::Drawable* drawable = child->asDrawable(); if (drawable) { bb.expandBy(drawable->getBoundingBox()); } else { const osg::BoundingSphere& bs = child->getBound(); bb.expandBy(bs); } } } if (!bb.valid()) { return bsphere; } bsphere._center = bb.center(); bsphere._radius = 0.0f; for(itr=_children.begin(); itr!=_children.end(); ++itr) { osg::Node* child = itr->get(); const osg::Transform* transform = child->asTransform(); if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF) { const BoundingSphere& bs = child->getBound(); bsphere.expandRadiusBy(bs); } } return bsphere; }
void BaseMesh::putIntoObjectSpace() { BoundingBox b = BaseMesh::calculateBBox(); setBBox(b); const Vector3F c = b.center(); const unsigned nv = getNumVertices(); for(unsigned i = 0; i < nv; i++) _vertices[i] -= c; }
bool ElementStore::store(const Element& element, const QuadKey& quadKey, const StyleProvider& styleProvider) { const BoundingBox expectedQuadKeyBbox = utymap::utils::GeoUtils::quadKeyToBoundingBox(quadKey); return store(element, LodRange(quadKey.levelOfDetail, quadKey.levelOfDetail), styleProvider, [&](const BoundingBox& elementBoundingBox, const BoundingBox& quadKeyBbox) { return elementBoundingBox.intersects(expectedQuadKeyBbox) && expectedQuadKeyBbox.center() == quadKeyBbox.center(); }); }
EditableSceneBodyImpl::EditableSceneBodyImpl(EditableSceneBody* self, BodyItemPtr& bodyItem) : self(self), bodyItem(bodyItem), kinematicsBar(KinematicsBar::instance()), modified(SgUpdate::MODIFIED) { pointedSceneLink = 0; outlinedLink = 0; targetLink = 0; positionDragger = new PositionDragger; positionDragger->setDraggerAlwaysShown(true); positionDragger->sigDragStarted().connect(boost::bind(&EditableSceneBodyImpl::onDraggerIKstarted, this)); positionDragger->sigPositionDragged().connect(boost::bind(&EditableSceneBodyImpl::onDraggerIKdragged, this)); dragMode = DRAG_NONE; isDragging = false; isEditMode = false; markerGroup = new SgGroup; markerGroup->setName("Marker"); self->addChild(markerGroup); double radius = 0; const int n = self->numSceneLinks(); for(int i=0; i < n; ++i){ SceneLink* sLink = self->sceneLink(i); BoundingBox bb = sLink->boundingBox(); double radius0 = (bb.max() - bb.center()).norm(); if(radius0 > radius){ radius = radius0; } } cmMarker = new CrossMarker(0.25, Vector3f(0.0f, 1.0f, 0.0f), 2.0); cmMarker->setName("centerOfMass"); cmMarker->setSize(radius); isCmVisible = false; LeggedBodyHelperPtr legged = getLeggedBodyHelper(self->body()); if(legged->isValid() && legged->numFeet() > 0){ Link* footLink = legged->footLink(0); const double r = calcLinkMarkerRadius(self->sceneLink(footLink->index())); zmpMarker = new SphereMarker(r, Vector3f(0.0f, 1.0f, 0.0f), 0.3); zmpMarker->setName("ZMP"); zmpMarker->addChild(new CrossMarker(r * 2.5, Vector3f(0.0f, 1.0f, 0.0f), 2.0f)); } else { zmpMarker = new SphereMarker(0.1, Vector3f(0.0f, 1.0f, 0.0f), 0.3); } isZmpVisible = false; self->sigGraphConnection().connect(boost::bind(&EditableSceneBodyImpl::onSceneGraphConnection, this, _1)); }
void BaseView::frameAll(const BoundingBox & b) { Vector3F eye = b.center(); eye.z = b.getMax(2) + b.distance(0) / hfov() * .55f + 120.f; setEyePosition(eye); Matrix44F m; m.setTranslation(eye); *cameraSpaceR() = m; m.inverse(); *cameraInvSpaceR() = m; setFrustum(1.33f, 1.f, 26.2f, -1.f, -1000.f); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool Labels::onInitialize() { // Add 3D geometry rendering // ------------------------------------------ ref<Part> cubePart = createCubePart(); ref<ModelBasicList> myModel = new ModelBasicList; cubePart->setPriority(1); myModel->addPart(cubePart.p()); addTextParts(myModel.p()); myModel->updateBoundingBoxesRecursive(); m_renderSequence->rendering(0)->scene()->addModel(myModel.p()); BoundingBox bb = m_renderSequence->boundingBox(); if (bb.isValid()) { m_camera->fitView(bb, -Vec3d::Z_AXIS, Vec3d::X_AXIS); m_trackball->setRotationPoint(bb.center()); } ref<OverlayAxisCross> axisCross = new OverlayAxisCross(m_camera.p(), new FixedAtlasFont(FixedAtlasFont::STANDARD)); m_renderSequence->firstRendering()->addOverlayItem(axisCross.p(), OverlayItem::BOTTOM_LEFT, OverlayItem::HORIZONTAL); ref<OverlayColorLegend> legend = new OverlayColorLegend(new FixedAtlasFont(FixedAtlasFont::STANDARD)); legend->setTitle("Legend title\nLegend unit"); legend->setColor(Color3::DARK_RED); m_renderSequence->firstRendering()->addOverlayItem(legend.p(), OverlayItem::TOP_LEFT, OverlayItem::VERTICAL); // Set up font // ------------------------------------------ CVF_ASSERT(m_font.isNull()); m_fontSize = CVF_SNIP_Labels_MIN_FONT_SIZE * 4; // Set up properties // ------------------------------------------ m_propFontName = new PropertyEnum("Font name"); m_propFontName->addItem(CVF_SNIP_Labels_FONT_B, CVF_SNIP_Labels_FONT_B); m_propFontName->addItem(CVF_SNIP_Labels_FONT_C, CVF_SNIP_Labels_FONT_C); m_propFontName->setCurrentIdent(CVF_SNIP_Labels_FONT_B); m_propertyPublisher->publishProperty(m_propFontName.p()); updateFont(m_propFontName->currentIdent()); m_propFontSize = new PropertyInt("Font size", m_fontSize); m_propFontSize->setRange(1, 36); m_propertyPublisher->publishProperty(m_propFontSize.p()); updateFont(m_fontSize); return true; }
void GridClustering::insertToGroup(const BoundingBox & box, const unsigned & idx) { const Vector3F center = box.center(); GroupCell * c = insertChild((const float *)¢er); if(!c) { std::cout<<"\n error cast to GroupCell"; return; } c->insert(idx); c->m_box.expandBy(box); }
void DepthComplexity3D::writeRaysSpherical(std::ostream& out, int k) { assert(_computeGoodRays); long long unsigned int total = 0; for(int i = 0 ; i <= k ; ++i) { const std::vector<Segment> & _rays = goodRays(maximum()-i); total += _rays.size(); } out << total << "\n"; /* Simple spherical coordinates for(int i = 0 ; i <= k ; ++i) { const std::vector<Segment> & _rays = goodRays(maximum()-i); std::vector<Segment>::const_iterator ite = _rays.begin(); std::vector<Segment>::const_iterator end = _rays.end(); for (; ite != end; ++ite) { double a, b, c, d; double x1 = ite->a.x, x2 = ite->b.x, y1 = ite->a.y, y2 = ite->b.y, z1 = ite->a.z, z2 = ite->b.z; a = atan2(y1, x1); b = atan2(z1, sqrt(x1*x1 + y1*y1)); c = atan2(y2, x2); d = atan2(z2, sqrt(x2*x2 + y2*y2)); out << a << " " << b << " " << c << " " << d << " " << maximum()-i << "\n"; } } */ BoundingBox aabb = _mesh->aabb; Sphere sph; sph.center = aabb.center(); sph.radius = aabb.extents().length()/2; // Coordinates of intersection with bounding sphere for(int i = 0 ; i <= k ; ++i) { const std::vector<Segment> & _rays = goodRays(maximum()-i); std::vector<Segment>::const_iterator ite = _rays.begin(); std::vector<Segment>::const_iterator end = _rays.end(); for (; ite != end; ++ite) { vec3d f, s; assert(segmentSphereIntersection3D(*ite,sph,f,s)); f = cartesianToSpherical(f); s = cartesianToSpherical(s); out << f.y << " " << f.z << " " << s.y << " " << s.z << " " << maximum()-i << "\n"; } } }
void BoundingSphere::expandRadiusBy(const BoundingBox& bb) { if (bb.valid()) { if (valid()) { for(unsigned int c=0;c<8;++c) { expandRadiusBy(bb.corner(c)); } } else { _center = bb.center(); _radius = bb.radius(); } } }
BoundingSphere Switch::computeBound() const { BoundingSphere bsphere; if (_children.empty()) { return bsphere; } // note, special handling of the case when a child is an Transform, // such that only Transforms which are relative to their parents coordinates frame (i.e this group) // are handled, Transform relative to and absolute reference frame are ignored. BoundingBox bb; bb.init(); for(unsigned int pos=0;pos<_children.size();++pos) { const osg::Transform* transform = _children[pos]->asTransform(); if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF) { if( _values[pos] == true ) bb.expandBy(_children[pos]->getBound()); } } if (!bb.valid()) { return bsphere; } bsphere._center = bb.center(); bsphere._radius = 0.0f; for(unsigned int pos=0;pos<_children.size();++pos) { const osg::Transform* transform = _children[pos]->asTransform(); if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF) { if( _values[pos] == true ) bsphere.expandRadiusBy(_children[pos]->getBound()); } } return bsphere; }
void GlMetaNodeTrueRenderer::render(node n,float lod,Camera* camera) { if(GlMetaNodeTrueRenderer::depth>=10000) return; if(lod<10) return; GlGraphInputData *inputDataBackup=inputData; inputData->getGlVertexArrayManager()->pauseRendering(true); glPushMatrix(); const Coord &nodeCoord = inputData->getElementLayout()->getNodeValue(n); const Size &nodeSize = inputData->getElementSize()->getNodeValue(n); glTranslatef(nodeCoord[0], nodeCoord[1], nodeCoord[2]); glRotatef(static_cast<float>(inputData->getElementRotation()->getNodeValue(n)), 0.f, 0.f, 1.f); Graph *metaGraph = inputData->getGraph()->getNodeMetaInfo(n); GlGraphRenderingParameters metaParameters = *inputData->parameters; GlGraphInputData metaData(metaGraph,&metaParameters); metaData.setMetaNodeRenderer(inputData->getMetaNodeRenderer()); metaData.setDeleteMetaNodeRendererAtDestructor(false); BoundingBox bboxes = tlp::computeBoundingBox(metaData.getGraph(), metaData.getElementLayout(), metaData.getElementSize(), metaData.getElementRotation()); Coord maxC(bboxes[1]); Coord minC(bboxes[0]); BoundingBox includeBoundingBox; inputData->glyphs.get(inputData->getElementShape()->getNodeValue(n))->getIncludeBoundingBox(includeBoundingBox,n); Coord includeScale(includeBoundingBox[1] - includeBoundingBox[0]); Coord includeTranslate(includeBoundingBox.center()); Coord translate( (maxC+minC)/-2.f); double dept; if(includeScale[2]==0) dept=0; else dept= (maxC[2] - minC[2]) / includeScale[2]; double width = (maxC[0] - minC[0]) / includeScale[0]; double height = (maxC[1] - minC[1]) / includeScale[1]; Coord includeSize(bboxes[1] - bboxes[0]); if(nodeSize[0]/includeSize[0]<nodeSize[1]/includeSize[1]) { includeSize[1]*=nodeSize[0]/includeSize[0]; includeSize[0]*=nodeSize[0]/includeSize[0]; } else { includeSize[0]*=nodeSize[1]/includeSize[1]; includeSize[1]*=nodeSize[1]/includeSize[1]; } if(includeSize[2]!=0) includeSize[2]*=nodeSize[2]/includeSize[2]; glScalef(includeSize[0], includeSize[1], includeSize[2]); glTranslatef(includeTranslate[0],includeTranslate[1],includeTranslate[2]-static_cast<float>(width/1000.)); if (width<0.0001) width=1; if (height<0.0001) height=1; if (dept<0.0001) dept=1; Coord scale(static_cast<float>(1/width),static_cast<float>(1/height),static_cast<float>(1/dept)); Camera *activeCamera; vector<Coord> objectScale, objectTranslate, objectCoord; activeCamera=new Camera(*camera); activeCamera->addObjectTransformation(nodeCoord+translate, Coord(includeSize*scale), nodeCoord); activeCamera->getObjectTransformation(objectTranslate, objectScale, objectCoord); GlCPULODCalculator calculator; calculator.setRenderingEntitiesFlag(RenderingAll); calculator.beginNewCamera(activeCamera); Iterator<node> *itN=metaGraph->getNodes(); GlNode glNode(0); while (itN->hasNext()) { glNode.id=itN->next().id; BoundingBox bb = glNode.getBoundingBox(&metaData); Coord size(bb[1] - bb[0]); Coord middle(bb[0] + size/2.f); for(int i=objectScale.size()-1; i>=0; --i) { middle+=objectTranslate[i]; middle=objectCoord[i] - (objectCoord[i]-middle)*objectScale[i]; size*=objectScale[i]; } bb[0] = middle-size/2.f; bb[1] = middle+size/2.f; calculator.addNodeBoundingBox(glNode.id,bb); } delete itN; if (metaData.parameters->isDisplayEdges()) { Iterator<edge> *itE=metaGraph->getEdges(); GlEdge glEdge(0); while (itE->hasNext()) { glEdge.id=itE->next().id; BoundingBox bb = glEdge.getBoundingBox(&metaData); Coord size(bb[1] - bb[0]); Coord middle(bb[0] + (size)/2.f); for(int i=objectScale.size()-1; i>=0; --i) { middle+=objectTranslate[i]; middle=objectCoord[i] - (objectCoord[i]-middle)*objectScale[i]; size*=objectScale[i]; } bb[0] = middle-size/2.f; bb[1] = middle+size/2.f; calculator.addEdgeBoundingBox(glEdge.id,bb); } delete itE; } calculator.compute(camera->getViewport(),camera->getViewport()); LayersLODVector &layersLODVector=calculator.getResult(); LayerLODUnit &layerLODUnit=layersLODVector.front(); glPushMatrix(); glScalef(scale[0],scale[1],scale[2]); glTranslatef(translate[0],translate[1],translate[2]); GlMetaNodeTrueRenderer::depth++; metaData.getMetaNodeRenderer()->setInputData(&metaData); metaData.getGlVertexArrayManager()->pauseRendering(true); GlMetaNode glMetaNode(0); GlEdge glEdge(0); for(vector<ComplexEntityLODUnit>::iterator it=layerLODUnit.nodesLODVector.begin(); it!=layerLODUnit.nodesLODVector.end(); ++it) { if((*it).lod<0) continue; metaData.getGlVertexArrayManager()->pauseRendering(true); if(!metaData.getGraph()->isMetaNode(node((*it).id))) { glNode.id=(*it).id; glNode.draw((*it).lod,&metaData,activeCamera); } else { glMetaNode.id=(*it).id; glMetaNode.draw((*it).lod,&metaData,activeCamera); } } metaData.getGlVertexArrayManager()->pauseRendering(true); for(vector<ComplexEntityLODUnit>::iterator it=layerLODUnit.edgesLODVector.begin(); it!=layerLODUnit.edgesLODVector.end(); ++it) { if((*it).lod<0) continue; glEdge.id=(*it).id; glEdge.draw((*it).lod,&metaData,activeCamera); } metaData.getMetaNodeRenderer()->setInputData(inputDataBackup); inputData->getGlVertexArrayManager()->pauseRendering(false); GlMetaNodeTrueRenderer::depth--; glPopMatrix(); glPopMatrix(); delete activeCamera; }
void NXOpenGLRenderingEngine::resetView(void) { // create axis-aligned bounding box if(currentFrameIndex < 0) return; NXMoleculeSet *molSetPtr = moleculeSets[currentFrameIndex]; BoundingBox bbox = GetBoundingBox(molSetPtr); Vector bboxMin = bbox.min(); Vector bboxMax = bbox.max(); real const bboxXWidth = 1.0*(bboxMax.x() - bboxMin.x()); real const bboxYWidth = 1.0*(bboxMax.y() - bboxMin.y()); real const bboxZDepth = 1.0*(bboxMax.z() - bboxMin.z()); real const projCubeWidth = max(bboxXWidth, max(bboxYWidth, bboxZDepth)); real const circumSphereRad = sqrt(3.0*0.25*projCubeWidth*projCubeWidth); // sqrt(sqr(max(bboxMax.x(), bboxMin.x())) + // sqr(max(bboxMax.y(), bboxMin.y())) + // sqr(max(bboxMax.z(), bboxMin.z())) ); real const circumSphereDia = 2.0 * circumSphereRad; Vector const bboxCenter = bbox.center(); real l, r, b, t; real const n = 0.25 * circumSphereRad; real const f = 12.0 * circumSphereRad; real const aspect = real(width()) / real(height()); if(aspect < 1.0) { // l = bboxCenter.x() - circumSphereDia; // r = bboxCenter.x() + circumSphereDia; // b = bboxCenter.y() - circumSphereDia / aspect; // t = bboxCenter.y() + circumSphereDia / aspect; l = -circumSphereRad; r = -l; b = -circumSphereRad / aspect; t = -b; } else { // l = bboxCenter.x() - aspect * circumSphereDia; // r = bboxCenter.x() + aspect * circumSphereDia; // b = bboxCenter.y() - circumSphereDia; // t = bboxCenter.y() + circumSphereDia; l = -aspect * circumSphereRad; r = -l; b = -circumSphereRad; t = -b; } // makeCurrent(); // camera.gluLookAt(bboxCenter.x(), bboxCenter.y(), // bboxCenter.z()+circumSphereDia, // bboxCenter.x(), bboxCenter.y(), bboxCenter.z(), // 0.0, 1.0, 0.0); // camera.gluPerspective(60.0, double(width())/double(height()), n, f); // camera.gluLookAt(0.0, 0.0, circumSphereRad, // 0.0, 0.0, 0.0, // 0.0, 1.0, 0.0); // camera.glOrtho(l, r, b, t, n, f); NXNamedView defaultView("DefaultView", NXQuaternion<double>(1.0, 0.0, 0.0, 1.0), bboxYWidth, NXVector3d(-bboxCenter.x(), -bboxCenter.y(), -bboxCenter.z()), 1.0); cerr << defaultView << endl; camera.setNamedView(defaultView); // default HomeView: (1, 0, 0, 0) (10) (0, 0, 0) (1) // orthographic projection as in GLPane.py::_setup_projection() // double const SCALE = 10.0 * 1.0e-13; // double const VDIST = 6.0 * SCALE; // camera.gluLookAt(0.0, 0.0, VDIST, // 0.0, 0.0, 0.0, // 0.0, 1.0, 0.0); // double const NEAR = 0.25, FAR = 12.0; // camera.glOrtho(-SCALE * aspect, SCALE * aspect, // -SCALE , SCALE, // VDIST * NEAR , VDIST * FAR); updateGL(); }
//======================================================================================== //======================================================================================== bool MouseSelectionEditor::computeFFD(GlMainWidget *glMainWidget) { if (!glMainWidget->getScene()->getGlGraphComposite() || !glMainWidget->getScene()->getGlGraphComposite()->getInputData()->getGraph()) return false; // We calculate the bounding box for the selection : initProxies(glMainWidget); BoundingBox boundingBox = tlp::computeBoundingBox(_graph, _layout, _sizes, _rotation, _selection); if (!boundingBox.isValid()) return false; if (operation == NONE) glMainWidget->setCursor(QCursor(Qt::PointingHandCursor)); Coord min2D, max2D; _layoutCenter = Coord(boundingBox.center()); // project the 8 points of the cube to obtain the bounding square on the 2D screen Coord bbsize(boundingBox[1] - boundingBox[0]); // v1 Coord tmp(boundingBox[0]); tmp = glMainWidget->getScene()->getGraphCamera().worldTo2DViewport(tmp); min2D = tmp; max2D = tmp; // v2, v3, V4 for (unsigned int i = 0; i < 3; ++i) { tmp = Coord(boundingBox[0]); tmp[i] += bbsize[i]; tmp = glMainWidget->getScene()->getGraphCamera().worldTo2DViewport(tmp); min2D = minCoord(tmp, min2D); max2D = maxCoord(tmp, max2D); } // v4 tmp = Coord(boundingBox[0]); tmp[0] += bbsize[0]; tmp[1] += bbsize[1]; tmp = glMainWidget->getScene()->getGraphCamera().worldTo2DViewport(tmp); min2D = minCoord(tmp, min2D); max2D = maxCoord(tmp, max2D); // v6 tmp = Coord(boundingBox[0]); tmp[0] += bbsize[0]; tmp[2] += bbsize[2]; tmp = glMainWidget->getScene()->getGraphCamera().worldTo2DViewport(tmp); min2D = minCoord(tmp, min2D); max2D = maxCoord(tmp, max2D); // v7 tmp = Coord(boundingBox[0]); tmp[1] += bbsize[1]; tmp[2] += bbsize[2]; tmp = glMainWidget->getScene()->getGraphCamera().worldTo2DViewport(tmp); min2D = minCoord(tmp, min2D); max2D = maxCoord(tmp, max2D); // v8 tmp = Coord(boundingBox[0]); tmp += bbsize; tmp = glMainWidget->getScene()->getGraphCamera().worldTo2DViewport(tmp); min2D = minCoord(tmp, min2D); max2D = maxCoord(tmp, max2D); ffdCenter = Coord(boundingBox.center()); Coord tmpCenter = glMainWidget->getScene()->getGraphCamera().worldTo2DViewport(ffdCenter); // qWarning() << tmpCenter << endl; // tmpCenter[0] = (double)glMainWidget->width() - tmpCenter[0]; // tmpCenter[1] = (double)glMainWidget->height() - tmpCenter[1]; // tmpCenter[1] = tmpCenter[1]; int x = int(max2D[0] - min2D[0]) / 2 + 1; // (+1) because selection use glLineWidth=3 thus int y = int(max2D[1] - min2D[1]) / 2 + 1; // the rectangle can be too small. if (x < 20) x = 18; if (y < 20) y = 18; Coord positions[8]; // we keep the z coordinate of the ffdCenter // to ensure a correct position of our controls (see GlHudPolygon.cpp) positions[0] = Coord(x, 0, ffdCenter[2]) + tmpCenter; // left positions[1] = Coord(x, -y, ffdCenter[2]) + tmpCenter; // Top left positions[2] = Coord(0, -y, ffdCenter[2]) + tmpCenter; // Top positions[3] = Coord(-x, -y, ffdCenter[2]) + tmpCenter; // Top r positions[4] = Coord(-x, 0, ffdCenter[2]) + tmpCenter; // r positions[5] = Coord(-x, y, ffdCenter[2]) + tmpCenter; // Bottom r positions[6] = Coord(0, y, ffdCenter[2]) + tmpCenter; // Bottom positions[7] = Coord(x, y, ffdCenter[2]) + tmpCenter; // Bottom l for (int i = 0; i < 8; i++) { positions[i][2] = 0; } // Parameters of the rectangle that shows the selected area. centerRect.setTopLeftPos(positions[1]); centerRect.setBottomRightPos(positions[5]); advRect.setTopLeftPos(positions[7] + Coord(-92, 16, 0)); advRect.setBottomRightPos(positions[7]); _controls[0].set(positions[0], 7, 0.0); // t _controls[1].set(positions[1], 6, float(M_PI) / 4.f); // c _controls[2].set(positions[2], 7, float(-M_PI) / 2.f); // t _controls[3].set(positions[3], 5, 0.); // s _controls[4].set(positions[4], 7, float(M_PI)); // t _controls[5].set(positions[5], 6, float(M_PI) / 4.f); // c _controls[6].set(positions[6], 7, float(M_PI) / 2.f); // _controls[7].set(positions[7], 5, 0.); // s vector<Coord> advControlVect; for (unsigned int i = 0; i < arrowWithLineSize; ++i) { advControlVect.push_back(arrowWithLine[i] + positions[7] + Coord(-11, 8, 0)); } _advControls[0] = GlComplexPolygon(advControlVect, Color(255, 40, 40, 200), Color(128, 20, 20, 200)); advControlVect.clear(); for (unsigned int i = 0; i < arrowWithLineSize; ++i) { advControlVect.push_back(Coord(arrowWithLine[i][0], -arrowWithLine[i][1], 0) + positions[7] + Coord(-25, 8, 0)); } _advControls[1] = GlComplexPolygon(advControlVect, Color(255, 40, 40, 200), Color(128, 20, 20, 200)); advControlVect.clear(); for (unsigned int i = 0; i < arrowWithLineSize; ++i) { advControlVect.push_back(Coord(-arrowWithLine[i][1], arrowWithLine[i][0], 0) + positions[7] + Coord(-39, 8, 0)); } _advControls[2] = GlComplexPolygon(advControlVect, Color(255, 40, 40, 200), Color(128, 20, 20, 200)); advControlVect.clear(); for (unsigned int i = 0; i < arrowWithLineSize; ++i) { advControlVect.push_back(Coord(arrowWithLine[i][1], arrowWithLine[i][0], 0) + positions[7] + Coord(-53, 8, 0)); } _advControls[3] = GlComplexPolygon(advControlVect, Color(255, 40, 40, 200), Color(128, 20, 20, 200)); advControlVect.clear(); for (unsigned int i = 0; i < twoArrowWithLineSize; ++i) { advControlVect.push_back(twoArrowWithLine[i] + positions[7] + Coord(-67, 8, 0)); } _advControls[4] = GlComplexPolygon(advControlVect, Color(255, 40, 40, 200), Color(128, 20, 20, 200)); advControlVect.clear(); for (unsigned int i = 0; i < twoArrowWithLineSize; ++i) { advControlVect.push_back(Coord(twoArrowWithLine[i][1], twoArrowWithLine[i][0], 0) + positions[7] + Coord(-81, 8, 0)); } _advControls[5] = GlComplexPolygon(advControlVect, Color(255, 40, 40, 200), Color(128, 20, 20, 200)); advControlVect.clear(); for (unsigned int i = 0; i < 6; ++i) { _advControls[i].setStencil(0); } return true; }
const Vector3F Geometry::boundingCenter() const { BoundingBox box = calculateBBox(); return box.center(); }
void GlMetaNode::drawLabel(OcclusionTest* test, GlGraphInputData* data, float lod, Camera *camera) { node n=node(id); if(data->parameters->isViewNodeLabel()) GlNode::drawLabel(test,data,lod,camera); if(!data->parameters->isViewMetaLabel()) return; if(!data->getMetaNodeRenderer()->glMetaNodeHaveToRenderLabels()) return; if(!data->parameters->isViewMetaLabel()) return; if((data->getElementColor()->getNodeValue(n))[3]==255) { return; } Graph *metaGraph = data->getGraph()->getNodeMetaInfo(n); GlGraphRenderingParameters metaParameters = *data->parameters; GlGraphInputData metaData(metaGraph,&metaParameters); vector<GlNode> nodes; vector<GlMetaNode> metaNodes; vector<GlEdge> edges; Iterator<node> *itN=metaGraph->getNodes(); unsigned int id; while (itN->hasNext()) { id=itN->next().id; if(metaData.getGraph()->isMetaNode(node(id))) metaNodes.push_back(GlMetaNode(id)); else nodes.push_back(GlNode(id)); } delete itN; if (metaData.parameters->isDisplayEdges()) { Iterator<edge> *itE=metaGraph->getEdges(); while (itE->hasNext()) { edges.push_back(GlEdge(itE->next().id)); } delete itE; } glPushMatrix(); const Coord &nodeCoord = data->getElementLayout()->getNodeValue(n); const Size &nodeSize = data->getElementSize()->getNodeValue(n); glTranslatef(nodeCoord[0], nodeCoord[1], nodeCoord[2]); glRotatef(static_cast<float>(data->getElementRotation()->getNodeValue(n)), 0.f, 0.f, 1.f); BoundingBox bboxes = tlp::computeBoundingBox(metaData.getGraph(), metaData.getElementLayout(), metaData.getElementSize(), metaData.getElementRotation()); Coord maxC(bboxes[1]); Coord minC(bboxes[0]); BoundingBox includeBoundingBox; data->glyphs.get(data->getElementShape()->getNodeValue(n))->getIncludeBoundingBox(includeBoundingBox,n); Coord includeScale(includeBoundingBox[1] - includeBoundingBox[0]); Coord includeTranslate(includeBoundingBox.center()); Coord translate( (maxC+minC)/-2.f); double dept; if(includeScale[2]==0) dept=0; else dept=(maxC[2] - minC[2]) / includeScale[2]; double width = (maxC[0] - minC[0]) / includeScale[0]; double height = (maxC[1] - minC[1]) / includeScale[1]; Coord includeSize( bboxes[1] - bboxes[0]); if(nodeSize[0]/includeSize[0]<nodeSize[1]/includeSize[1]) { includeSize[1] *= nodeSize[0]/includeSize[0]; includeSize[0] *= nodeSize[0]/includeSize[0]; } else { includeSize[0]*=nodeSize[1]/includeSize[1]; includeSize[1]*=nodeSize[1]/includeSize[1]; } glScalef(includeSize[0], includeSize[1], includeSize[2]); glTranslatef(includeTranslate[0],includeTranslate[1],includeTranslate[2]); if (width<0.0001) width=1; if (height<0.0001) height=1; if (dept<0.0001) dept=1; Coord scale(1/static_cast<float>(width),1/static_cast<float>(height),1/static_cast<float>(dept)); glScalef(scale[0], scale[1], scale[2]); glTranslatef(translate[0],translate[1],translate[2]); vector<Coord> objectScale, objectTranslate, objectCoord; Camera *activeCamera=new Camera(*camera); activeCamera->addObjectTransformation(nodeCoord+translate, Coord(includeSize*scale), nodeCoord); activeCamera->getObjectTransformation(objectTranslate, objectScale, objectCoord); for(vector<GlNode>::iterator it=nodes.begin(); it!=nodes.end(); ++it) { (*it).drawLabel(test,&metaData,1000,camera); } for(vector<GlMetaNode>::iterator it=metaNodes.begin(); it!=metaNodes.end(); ++it) { (*it).drawLabel(test,&metaData,1000,camera); } for(vector<GlEdge>::iterator it=edges.begin(); it!=edges.end(); ++it) { (*it).drawLabel(test,&metaData); } glPopMatrix(); }
ZoomAndPanAnimation::ZoomAndPanAnimation(Camera *camera, const BoundingBox &boundingBox, const unsigned int animationDuration, const bool optimalPath, const float velocity, const double p) : _camera(camera),_viewport(camera->getViewport()), _animationDuration(animationDuration), _optimalPath(optimalPath), _p(p), _camCenterStart(camera->getCenter()),_camCenterEnd(Coord(boundingBox.center())) { if (boundingBox.width() == 0 || boundingBox.height() == 0) { _doZoomAndPan = false; return; } _camCenterEnd[2] = _camCenterStart[2]; Coord blScene(camera->screenTo3DWorld(Coord(0, 0, 0))); Coord trScene(camera->screenTo3DWorld(Coord(_viewport[2], _viewport[3], 0))); BoundingBox sceneBB; sceneBB.expand(blScene); sceneBB.expand(trScene); _zoomAreaWidth = boundingBox[1][0] - boundingBox[0][0]; _zoomAreaHeight = boundingBox[1][1] - boundingBox[0][1]; float aspectRatio = _viewport[2] / static_cast<float>(_viewport[3]); if (_zoomAreaWidth > (aspectRatio * _zoomAreaHeight)) { _w0 = sceneBB[1][0] - sceneBB[0][0]; _w1 = _zoomAreaWidth; } else { _w0 = sceneBB[1][1] - sceneBB[0][1]; _w1 = _zoomAreaHeight; } _u0 = 0; _u1 = _camCenterStart.dist(_camCenterEnd); if (_u1 < 1e-5) _u1 = 0; if (optimalPath) { if (_u0 != _u1) { _b0 = (_w1 * _w1 - _w0 * _w0 + p * p * p * p * _u1 * _u1) / (2 * _w0 * p * p * _u1); _b1 = (_w1 * _w1 - _w0 * _w0 - p * p * p * p * _u1 * _u1) / (2 * _w1 * p * p * _u1); _r0 = log(-_b0 + sqrt(_b0 * _b0 + 1)); _r1 = log(-_b1 + sqrt(_b1 * _b1 + 1)); _S = (_r1 - _r0) / p; } else { _S = abs(log(_w1 / _w0)) / p; } } else { _wm = max(_w0, max(_w1, p * p * (_u1 - _u0) / 2)); _sA = log(_wm / _w0) / p; _sB = _sA + p * (_u1 - _u0) / _wm; _S = _sB + log(_wm / _w1) / p; } if (abs(_w0 - _w1) > 1e-3 || _u1 > 0) { _doZoomAndPan = true; } else { _doZoomAndPan = false; } _animationDuration *= _S/velocity; }
void GlNode::drawLabel(OcclusionTest* test,GlGraphInputData* data,float lod, Camera *camera) { node n=node(id); // If glyph can't render label : return if(data->glyphs.get(data->getElementShape()->getNodeValue(n))->renderLabel()) return; // node is selected bool selected=data->getElementSelected()->getNodeValue(n); // Color of the label : selected or not const Color& fontColor = selected ? data->parameters->getSelectionColor() :data->getElementLabelColor()->getNodeValue(n); // If we have transparent label : return if(fontColor.getA()==0) return; // Node text const string &tmp = data->getElementLabel()->getNodeValue(n); if (tmp.length() < 1) return; if(!data->getGraph()->isMetaNode(n)) { if(selected) label->setStencil(data->parameters->getSelectedNodesStencil()); else label->setStencil(data->parameters->getNodesLabelStencil()); } else { if(selected) label->setStencil(data->parameters->getSelectedMetaNodesStencil()); else label->setStencil(data->parameters->getMetaNodesLabelStencil()); } int fontSize=data->getElementFontSize()->getNodeValue(n); if(fontSize<=0) return; if(selected) fontSize+=2; const Coord &nodeCoord = data->getElementLayout()->getNodeValue(n); const Size &nodeSize = data->getElementSize()->getNodeValue(n); int labelPos = data->getElementLabelPosition()->getNodeValue(n); BoundingBox includeBB; data->glyphs.get(data->getElementShape()->getNodeValue(n))->getTextBoundingBox(includeBB,n); Coord centerBB(includeBB.center()); Vec3f sizeBB = includeBB[1]-includeBB[0]; label->setFontNameSizeAndColor(data->getElementFont()->getNodeValue(n),fontSize,fontColor); label->setOutlineColor(fontColor); label->setText(tmp); label->setTranslationAfterRotation(centerBB*nodeSize); label->setSize(Size(nodeSize[0]*sizeBB[0],nodeSize[1]*sizeBB[1],0)); label->setSizeForOutAlign(Size(nodeSize[0],nodeSize[1],0)); label->rotate(0,0,static_cast<float>(data->getElementRotation()->getNodeValue(n))); label->setAlignment(labelPos); label->setScaleToSize(data->parameters->isLabelScaled()); label->setUseLODOptimisation(true,this->getBoundingBox(data)); label->setLabelsDensity(data->parameters->getLabelsDensity()); label->setUseMinMaxSize(true); label->setMinSize(data->parameters->getMinSizeOfLabel()); label->setMaxSize(data->parameters->getMaxSizeOfLabel()); label->setOcclusionTester(test); label->setBillboarded(data->parameters->getLabelsAreBillboarded()); if(includeBB[1][2]!=0 && !data->parameters->getLabelsAreBillboarded()) label->setPosition(Coord(nodeCoord[0],nodeCoord[1],nodeCoord[2]+nodeSize[2]/2.f)); else label->setPosition(Coord(nodeCoord[0],nodeCoord[1],nodeCoord[2])); label->drawWithStencil(lod,camera); }
/// Gets scaled value. static double getScaled(const BoundingBox &bbox, double scale, double value) { return getOffset(bbox.center(), value)*scale/bbox.width(); }