本文整理汇总了C++中BoundingBox::expand方法的典型用法代码示例。如果您正苦于以下问题:C++ BoundingBox::expand方法的具体用法?C++ BoundingBox::expand怎么用?C++ BoundingBox::expand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundingBox
的用法示例。
在下文中一共展示了BoundingBox::expand方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getBoundingBox
BoundingBox GlMatrixBackgroundGrid::getBoundingBox() {
int N = _view->graph()->numberOfNodes();
BoundingBox result;
result.expand(Coord(0,0,0));
result.expand(Coord(1+N,-1-N,0));
return result;
}
示例2: getBoundingBox
BoundingBox GlNode::getBoundingBox(GlGraphInputData* data) {
node n=node(id);
if(data->getElementRotation()->getNodeValue(n)==0) {
BoundingBox box;
box.expand(data->getElementLayout()->getNodeValue(n)-data->getElementSize()->getNodeValue(n)/2.f);
box.expand(data->getElementLayout()->getNodeValue(n)+data->getElementSize()->getNodeValue(n)/2.f);
assert(box.isValid());
return box;
}
else {
float cosAngle=static_cast<float>(cos(data->getElementRotation()->getNodeValue(n)/180.*M_PI));
float sinAngle=static_cast<float>(sin(data->getElementRotation()->getNodeValue(n)/180.*M_PI));
Coord tmp1(data->getElementSize()->getNodeValue(n)/2.f);
Coord tmp2(tmp1[0] ,-tmp1[1], tmp1[2]);
Coord tmp3(-tmp1[0],-tmp1[1],-tmp1[2]);
Coord tmp4(-tmp1[0], tmp1[1],-tmp1[2]);
tmp1=Coord(tmp1[0]*cosAngle-tmp1[1]*sinAngle,tmp1[0]*sinAngle+tmp1[1]*cosAngle,tmp1[2]);
tmp2=Coord(tmp2[0]*cosAngle-tmp2[1]*sinAngle,tmp2[0]*sinAngle+tmp2[1]*cosAngle,tmp2[2]);
tmp3=Coord(tmp3[0]*cosAngle-tmp3[1]*sinAngle,tmp3[0]*sinAngle+tmp3[1]*cosAngle,tmp3[2]);
tmp4=Coord(tmp4[0]*cosAngle-tmp4[1]*sinAngle,tmp4[0]*sinAngle+tmp4[1]*cosAngle,tmp4[2]);
BoundingBox bb;
bb.expand(data->getElementLayout()->getNodeValue(n)+tmp1);
bb.expand(data->getElementLayout()->getNodeValue(n)+tmp2);
bb.expand(data->getElementLayout()->getNodeValue(n)+tmp3);
bb.expand(data->getElementLayout()->getNodeValue(n)+tmp4);
return bb;
}
}
示例3: getBoundingBox
BoundingBox BSPTree::getBoundingBox()
{
BoundingBox sceneBox;
ObjectList::iterator o;
for (o=m_kObjects.begin();o!=m_kObjects.end();o++){
BoundingBox objBox = ((*o)->getBoundingBox());
sceneBox.expand(objBox);
}
return sceneBox;
}
示例4: RenderGroup
BoundingBox RenderGroup(SceneGroup *i, vec3 color, int lod, int depth)
{
int ii;
BoundingBox bbox;
// if this is a terminal node
if (i->getChildCount() == 0) {
// set the correct color for the polygon
glColor3f(color[0],color[1],color[2]);
// draw the polygon if LOD == 3
if (lod == 3)
i->getPolygon()->draw(GL_POLYGON);
// draw the polygon outline if LOD == 2
else if (lod == 2)
i->getPolygon()->draw(GL_LINE_LOOP);
// draw the bounding box
setColor(depth);
i->getPolygon()->getBoundingBox().draw();
// return the polygon's bounding box
return i->getPolygon()->getBoundingBox();
} else {
// expand and traverse this node
for(ii=0; ii<i->getChildCount();ii++)
bbox.expand(RenderInstance(i->getChild(ii), color, lod, depth+1));
// draw this group's bounding box
setColor(depth);
bbox.draw();
}
return bbox;
}
示例5: renderOneLabel
void LabelsRenderer::renderOneLabel(const Camera &camera, const string &text, const BoundingBox &renderingBox, const Color &labelColor) {
initFont();
if (text.empty()) return;
BoundingBox textBBScaled = getLabelRenderingBoxScaled(renderingBox, getTextAspectRatio(text));
Vec4i viewport = camera.getViewport();
Vec2f textBBMinScr = computeScreenPos(camera.transformMatrix(), viewport, textBBScaled[0]);
Vec2f textBBMaxScr = computeScreenPos(camera.transformMatrix(), viewport, textBBScaled[1]);
BoundingBox bb;
bb.expand(Vec3f(textBBMinScr[0], viewport[3] - textBBMinScr[1]));
bb.expand(Vec3f(textBBMaxScr[0], viewport[3] - textBBMaxScr[1]));
NVGcontext* vg = NanoVGManager::instance()->getNanoVGContext();
nvgBeginFrame(vg, camera.getViewport()[0], camera.getViewport()[1], camera.getViewport()[2], camera.getViewport()[3], 1.0);
renderText(vg, text, bb, labelColor);
nvgEndFrame(vg);
}
示例6: in
ClusterVisualizer::ClusterVisualizer(string filename)
{
ifstream in(filename.c_str());
// Check!
if(!in.good()) return;
MeshCluster* cluster = new MeshCluster;
// Read sub meshes
while(in.good())
{
string cluster_name;
int num_faces;
int num_vertices;
// Read 'header'
in >> cluster_name;
in >> num_faces >> num_vertices;
BoundingBox<Vertex<float> > bb;
// Alloc buffers
if(num_faces && num_vertices)
{
floatArr vertices(new float[3 * num_vertices]);
floatArr normals(new float[3 * num_vertices]);
ucharArr colors(new uchar[3 * num_vertices]);
uintArr indices(new uint[3 * num_faces]);
// Read indices
for(int i = 0; i < num_faces; i++)
{
int pos = 3 * i;
uint a, b, c;
in >> a >> b >> c;
indices[pos ] = a;
indices[pos + 1] = b;
indices[pos + 2] = c;
}
// Read vertices, normals and colors
for(int i = 0; i < num_vertices; i++)
{
int pos = 3 * i;
float x, y, z, nx, ny, nz;
int r, g, b;
in >> x >> y >> z >> nx >> ny >> nz >> r >> g >> b;
vertices[pos ] = x;
vertices[pos + 1] = y;
vertices[pos + 2] = z;
normals[pos ] = nx;
normals[pos + 1] = ny;
normals[pos + 2] = nz;
colors[pos ] = (uchar)r;
colors[pos + 1] = (uchar)g;
colors[pos + 2] = (uchar)b;
bb.expand(x, y, z);
}
// Create Buffer
MeshBufferPtr* buffer = new MeshBufferPtr(new MeshBuffer);
buffer->get()->setVertexArray(vertices, num_vertices);
buffer->get()->setVertexNormalArray(normals, num_vertices);
buffer->get()->setVertexColorArray(colors, num_vertices);
buffer->get()->setFaceArray(indices, num_faces);
cluster->boundingBox()->expand(bb);
cluster->addMesh(*buffer, cluster_name);
}
}
示例7: selectGraphElementsUnderPolygon
void MouseLassoNodesSelectorInteractorComponent::selectGraphElementsUnderPolygon(GlMainWidget *glWidget) {
vector<Coord> polygonVprt;
BoundingBox polygonVprtBB;
for (unsigned int i = 0 ; i < polygon.size() ; ++i) {
polygonVprt.push_back(polygon[i]);
polygonVprtBB.expand(polygonVprt[i]);
}
polygonVprt.push_back(polygon[0]);
int xStart = (int) polygonVprtBB[0][0];
int yStart = (int) polygonVprtBB[0][1];
int xEnd = (int) polygonVprtBB[1][0];
int yEnd = (int) polygonVprtBB[1][1];
vector<SelectedEntity> tmpNodes;
vector<SelectedEntity> tmpEdges;
glWidget->pickNodesEdges(glWidget->viewportToScreen(xStart), glWidget->height() - glWidget->viewportToScreen(yEnd), glWidget->viewportToScreen(xEnd - xStart), glWidget->viewportToScreen(yEnd - yStart), tmpNodes, tmpEdges);
if (!tmpNodes.empty()) {
vector<node> selectedNodes;
GlNode glNode(0);
bool needPush = true;
for (unsigned int i = 0 ; i < tmpNodes.size() ; ++i) {
glNode.id = tmpNodes[i].getComplexEntityId();
BoundingBox nodeBB(glNode.getBoundingBox(glWidget->getScene()->getGlGraphComposite()->getInputData()));
float dx = nodeBB[1][0] - nodeBB[0][0];
float dy = nodeBB[1][1] - nodeBB[0][1];
float dz = nodeBB[1][2] - nodeBB[0][2];
const float f = 0.2f;
nodeBB[0][0] = nodeBB[0][0] + f * dx;
nodeBB[0][1] = nodeBB[0][1] + f * dy;
nodeBB[0][2] = nodeBB[0][2] + f * dz;
nodeBB[1][0] = nodeBB[1][0] - f * dx;
nodeBB[1][1] = nodeBB[1][1] - f * dy;
nodeBB[1][2] = nodeBB[1][2] - f * dz;
vector<float> xVec;
vector<float> yVec;
Coord nodeBBBLBScr(camera->worldTo2DViewport(Coord(nodeBB[0])));
xVec.push_back(nodeBBBLBScr.getX());
yVec.push_back(nodeBBBLBScr.getY());
Coord nodeBBTLBScr(camera->worldTo2DViewport(Coord(nodeBB[0][0], nodeBB[1][1], nodeBB[0][2])));
xVec.push_back(nodeBBTLBScr[0]);
yVec.push_back(nodeBBTLBScr[1]);
Coord nodeBBTRBScr(camera->worldTo2DViewport(Coord(nodeBB[1][0], nodeBB[1][1], nodeBB[0][2])));
xVec.push_back(nodeBBTRBScr[0]);
yVec.push_back(nodeBBTRBScr[1]);
Coord nodeBBBRBScr(camera->worldTo2DViewport(Coord(nodeBB[1][0], nodeBB[0][1], nodeBB[0][2])));
xVec.push_back(nodeBBBRBScr[0]);
yVec.push_back(nodeBBBRBScr[1]);
Coord nodeBBBLFScr(camera->worldTo2DViewport(Coord(nodeBB[0][0], nodeBB[0][1], nodeBB[1][2])));
xVec.push_back(nodeBBBLFScr[0]);
yVec.push_back(nodeBBBLFScr[1]);
Coord nodeBBTLFScr(camera->worldTo2DViewport(Coord(nodeBB[0][0], nodeBB[1][1], nodeBB[1][2])));
xVec.push_back(nodeBBTLFScr[0]);
yVec.push_back(nodeBBTLFScr[1]);
Coord nodeBBTRFScr(camera->worldTo2DViewport(Coord(nodeBB[1])));
xVec.push_back(nodeBBTRFScr[0]);
yVec.push_back(nodeBBTRFScr[1]);
Coord nodeBBBRFScr(camera->worldTo2DViewport(Coord(nodeBB[1][0], nodeBB[0][1], nodeBB[1][2])));
xVec.push_back(nodeBBBRFScr[0]);
yVec.push_back(nodeBBBRFScr[1]);
vector<Coord> quad;
quad.push_back(Coord(*min_element(xVec.begin(), xVec.end()), *min_element(yVec.begin(), yVec.end())));
quad.push_back(Coord(*min_element(xVec.begin(), xVec.end()), *max_element(yVec.begin(), yVec.end())));
quad.push_back(Coord(*max_element(xVec.begin(), xVec.end()), *max_element(yVec.begin(), yVec.end())));
quad.push_back(Coord(*max_element(xVec.begin(), xVec.end()), *min_element(yVec.begin(), yVec.end())));
quad.push_back(quad[0]);
if (isPolygonAincludesInB(quad, polygonVprt)) {
if (needPush) {
viewSelection->getGraph()->push();
needPush = false;
}
viewSelection->setNodeValue(node(tmpNodes[i].getComplexEntityId()), true);
selectedNodes.push_back(node(tmpNodes[i].getComplexEntityId()));
}
}
for (unsigned int i = 0 ; i < selectedNodes.size() ; ++i) {
for (unsigned int j = i+1 ; j < selectedNodes.size() ; ++j) {
vector<edge> edges = graph->getEdges(selectedNodes[i], selectedNodes[j], false);
for (size_t i = 0 ; i < edges.size() ; ++i) {
viewSelection->setEdgeValue(edges[i], true);
}
}
}
}
}
示例8: blScene
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;
}
示例9: recursiveTreeConstructor
nikita::BVHNodePtr BVH::recursiveTreeConstructor(std::vector<BVHObject> &objectList,
unsigned int begin,
unsigned int end,
unsigned int *totalNodes,
std::vector<GeoPrimPtr> &orderedObjects)
{
(*totalNodes)++;
BVHNodePtr node = std::make_shared<BVHNode>();
// compute the bounding boxes of all primitives in this node
BBoxPtr bbox = std::make_shared<BoundingBox>();
for (int i = begin; i < end; ++i) {
bbox = std::make_shared<BoundingBox>(BoundingBox::U(*bbox, *objectList[i].bbox));
}
unsigned int numberPrimitives = end - begin;
if (numberPrimitives == 1) {
// create a leaf node
unsigned int firstPrimOffset = orderedObjects.size();
for (unsigned int i = begin; i < end; ++i) {
unsigned int shapeNum = objectList[i].objectNumber;
orderedObjects.push_back(objects[shapeNum]);
}
node->initLeaf(firstPrimOffset, numberPrimitives, bbox);
}
else {
// compute the bounding boxes of the primitives centroids, and choose the dimension to split on
BoundingBox centroidBound;
for (int i = begin; i < end; ++i)
centroidBound = centroidBound.expand(objectList[i].centroid);
int dimension = centroidBound.maximumDimension();
// partition the primitives into two sets, and build the children accordingly
int midpoint = (begin + end) / 2;
if (centroidBound.pMax(dimension) == centroidBound.pMin(dimension)) {
// create leaf node
// if the remaining primitives fit in a single node, do it here
if (numberPrimitives <= maxPrimsLeaf)
{
unsigned int firstShapeOffset = orderedObjects.size();
for (int i = begin; i < end; ++i) {
unsigned int shapeNum = objectList[i].objectNumber;
orderedObjects.push_back(objects[shapeNum]);
}
node->initLeaf(firstShapeOffset, numberPrimitives, bbox);
return node;
}
else
{
// otherwise, it has to be split again
node->initInterior(dimension,
recursiveTreeConstructor(objectList, begin, midpoint,
totalNodes, orderedObjects),
recursiveTreeConstructor(objectList, midpoint, end,
totalNodes, orderedObjects));
return node;
}
}
midpoint = (begin + end) / 2;
std::nth_element(&objectList[begin], &objectList[midpoint], &objectList[end-1]+1,
BVHComparePoints(dimension));
node->initInterior(dimension,
recursiveTreeConstructor(objectList, begin, midpoint,
totalNodes, orderedObjects),
recursiveTreeConstructor(objectList, midpoint, end,
totalNodes, orderedObjects));
}
return node;
}
示例10: voxelize
arma::cube voxelize(std::vector<CylinderFrustum> cylinders, const Transform &transform, const BoundingBox &boundingBox, int maxExtent)
{
Length xSide = boundingBox.pMax[0] - boundingBox.pMin[0];
Length ySide = boundingBox.pMax[1] - boundingBox.pMin[1];
Length zSide = boundingBox.pMax[2] - boundingBox.pMin[2];
Length maxLen = max(xSide, max(ySide, zSide));
double xRatio = xSide / maxLen;
double yRatio = ySide / maxLen;
double zRatio = zSide / maxLen;
// x = col, y = row, z = slice
arma::cube voxels = arma::zeros(maxExtent * yRatio, maxExtent * xRatio, maxExtent * zRatio);
Length3D offset(boundingBox.pMin);
for(CylinderFrustum& cylinder : cylinders) {
cylinder = CylinderFrustum(cylinder.start - offset,
cylinder.end - offset,
cylinder.startRadius,
cylinder.endRadius);
}
for(CylinderFrustum& cylinder : cylinders) {
cylinder = CylinderFrustum(transform(cylinder.start),
transform(cylinder.end),
cylinder.startRadius,
cylinder.endRadius);
}
Length step = maxLen / double(maxExtent - 2);
Length eps = step; // / 2.0;
for(CylinderFrustum& cylinder : cylinders) {
BoundingBox localBounds(Point3D(-cylinder.h, -cylinder.startRadius, -cylinder.startRadius),
Point3D(cylinder.h, cylinder.startRadius, cylinder.startRadius));
Vector3D perpendicular = cross(Vector3D(1.0, 0.0, 0.0), cylinder.direction);
Transform rotation;
double sinAngle = perpendicular.length();
if(sinAngle > 0.0) {
if(sinAngle > 1.0) {
sinAngle -= 2.2204460492503131e-16; // typical machine precision error
}
double cosAngle = sqrt(1.0 - sinAngle*sinAngle);
rotation = rotate(cosAngle, sinAngle, perpendicular);
}
Transform translation = translate(Length3D(cylinder.center));
BoundingBox bounds = translation(rotation(localBounds));
bounds.expand(eps);
int istart = bounds.pMin.x / step;
int jstart = bounds.pMin.y / step;
int kstart = bounds.pMin.z / step;
int iend = bounds.pMax.x / step + 1;
int jend = bounds.pMax.y / step + 1;
int kend = bounds.pMax.z / step + 1;
for(int i = istart; i < iend + 1; i++) {
for(int j = jstart; j < jend + 1; j++) {
for(int k = kstart; k < kend + 1; k++) {
Point3D p(step * (double(i) + 0.5), step * (double(j) + 0.5), step * (double(k) + 0.5));
Length3D diff = p - cylinder.center;
Length distance = diff.length();
if(distance > cylinder.h + eps && distance > cylinder.startRadius + eps) {
continue;
}
auto yComponent = dot(diff, cylinder.direction * 1.0_um) / 1.0_um;
if(fabs(yComponent) <= cylinder.h + eps) {
auto y2 = yComponent*yComponent;
auto diff2 = dot(diff, diff);
auto distanceToAxis = sqrt(diff2 - y2);
double endProportion = (yComponent + cylinder.h) / (2.0 * cylinder.h);
Length radius = cylinder.startRadius * (1 - endProportion) + endProportion * cylinder.endRadius;
if(distanceToAxis <= radius + eps) {
if(voxels.in_range(j, i, k)) {
voxels(j, i, k) = 1.0;
}
}
}
}
}
}
}
return voxels;
}
示例11: renderGraphNodesLabels
void LabelsRenderer::renderGraphNodesLabels(Graph *graph, const Camera &camera, const Color &selectionColor) {
initFont();
BooleanProperty *viewSelection = graph->getProperty<BooleanProperty>("viewSelection");
ColorProperty *viewLabelColor = graph->getProperty<ColorProperty>("viewLabelColor");
StringProperty *viewLabel = graph->getProperty<StringProperty>("viewLabel");
Vec4i viewport = camera.getViewport();
vector<vector<Vec2f> > renderedLabelsScrRect;
vector<BoundingBox> renderedLabelsScrBB;
NVGcontext* vg = NanoVGManager::instance()->getNanoVGContext();
nvgBeginFrame(vg, camera.getViewport()[0], camera.getViewport()[1], camera.getViewport()[2], camera.getViewport()[3], 1.0);
for (vector<node>::iterator it = _labelsToRender[graph].begin() ; it != _labelsToRender[graph].end() ; ++it) {
if (_nodeLabelAspectRatio[graph].find(*it) == _nodeLabelAspectRatio[graph].end()) {
continue;
}
BoundingBox nodeBB = labelBoundingBoxForNode(graph, *it);
BoundingBox textBB = getLabelRenderingBoxScaled(nodeBB, _nodeLabelAspectRatio[graph][*it]);
if (!_labelsScaled) {
adjustTextBoundingBox(textBB, camera, _minSize, _maxSize, _nodeLabelNbLines[graph][*it]);
}
bool canRender = true;
if (_occlusionTest) {
if (!camera.hasRotation()) {
BoundingBox textScrBB;
textScrBB.expand(Vec3f(computeScreenPos(camera.transformMatrixBillboard(), viewport, textBB[0]), 0));
textScrBB.expand(Vec3f(computeScreenPos(camera.transformMatrixBillboard(), viewport, textBB[1]), 0));
for (size_t i = 0 ; i < renderedLabelsScrBB.size() ; ++i) {
if (textScrBB.intersect(renderedLabelsScrBB[i])) {
canRender = false;
break;
}
}
if (canRender) {
renderedLabelsScrBB.push_back(textScrBB);
}
} else {
vector<Vec2f> textScrRect;
textScrRect.push_back(computeScreenPos(camera.transformMatrix(), viewport, textBB[0]));
textScrRect.push_back(computeScreenPos(camera.transformMatrix(), viewport, Vec3f(textBB[0][0]+textBB.width(), textBB[0][1], textBB[0][2])));
textScrRect.push_back(computeScreenPos(camera.transformMatrix(), viewport, textBB[1]));
textScrRect.push_back(computeScreenPos(camera.transformMatrix(), viewport, Vec3f(textBB[0][0], textBB[0][1]+textBB.height(), textBB[0][2])));
for (size_t i = 0 ; i < renderedLabelsScrRect.size() ; ++i) {
if (convexPolygonsIntersect(textScrRect, renderedLabelsScrRect[i])) {
canRender = false;
break;
}
}
if (canRender) {
renderedLabelsScrRect.push_back(textScrRect);
}
}
}
if (canRender) {
Vec2f textBBMinScr = computeScreenPos(camera.transformMatrix(), viewport, textBB[0]);
Vec2f textBBMaxScr = computeScreenPos(camera.transformMatrix(), viewport, textBB[1]);
BoundingBox bb;
bb.expand(Vec3f(textBBMinScr[0], viewport[3] - textBBMinScr[1]));
bb.expand(Vec3f(textBBMaxScr[0], viewport[3] - textBBMaxScr[1]));
renderText(vg, viewLabel->getNodeValue(*it), bb, viewSelection->getNodeValue(*it) ? selectionColor : viewLabelColor->getNodeValue(*it));
}
}
nvgEndFrame(vg);
}
示例12: build
//.........这里部分代码省略.........
mColorTexPtr->Load(image);
// build the color rt
mColorRTPtr = GNEW(Target(mColorTexPtr.Ptr()));
CHECK(mColorRTPtr);
// build the primitive
mQuadPtr = GNEW(Primitive);
CHECK(mQuadPtr);
mQuadPtr->SetType(Primitive::PT_TRIANGLES);
// set the wvp
Constant* wvp_constant_ptr = GNEW(Constant);
CHECK(wvp_constant_ptr);
wvp_constant_ptr->SetMatrix(Matrix());
mQuadPtr->SetConstant("gWVP",wvp_constant_ptr);
// set the color texture
Constant* texture_constant_ptr = GNEW(Constant);
CHECK(texture_constant_ptr);
texture_constant_ptr->SetTexture(mColorTexPtr.Ptr());
mQuadPtr->SetConstant("gBaseTex",texture_constant_ptr);
// set the shader
Str shader_key_name = "shader/default.xml";
KeyPtr shader_key_ptr = Key::Find(shader_key_name.c_str());
if(shader_key_ptr == NULL)
{
Shader*shader = GNEW(Shader);
CHECK(shader);
shader->Load(GLoad(shader_key_name.c_str()));
shader_key_ptr = GNEW(Key(shader_key_name.c_str(), shader));
CHECK(shader_key_ptr);
}
mKeys.push_back(shader_key_ptr);
mQuadPtr->SetShader(dynamic_cast<Shader*>(shader_key_ptr->Ptr()),"p0");
// build the vertex buffer
F32 x = 0.0f, y = 0.0f, w = 256, h = 256;
DVT vertexes[] =
{
{x, y, 0, 0, 0},
{x+w, y, 0, 1, 0},
{x+w, y+h, 0, 1, 1},
{x, y+h, 0, 0, 1},
};
VertexBufferPtr vb_ptr = GNEW(VertexBuffer);
CHECK(vb_ptr);
{
GDataPtr vd_ptr = GNEW(GData);
CHECK(vd_ptr);
vd_ptr->Size(3*sizeof(U32) + 3*sizeof(U8) + sizeof(vertexes));
U8*data_ptr = (U8*)vd_ptr->Ptr();
*(U32*)data_ptr = MAKEFOURCC('G','V','B','O');
data_ptr += sizeof(U32);
*(U32*)data_ptr = sizeof(vertexes)/sizeof(DVT);
data_ptr += sizeof(U32);
*(U32*)data_ptr = sizeof(DVT);
data_ptr += sizeof(U32);
*(U8*)data_ptr = 2;
data_ptr += sizeof(U8);
*(U8*)data_ptr = VertexBuffer::VT_3F;
data_ptr += sizeof(U8);
*(U8*)data_ptr = VertexBuffer::VT_2F;
data_ptr += sizeof(U8);
::memcpy(data_ptr, vertexes, sizeof(vertexes));
data_ptr += sizeof(vertexes);
vb_ptr->Load(vd_ptr.Ptr());
}
mQuadPtr->SetVertexBuffer(vb_ptr.Ptr());
// build the index
const U16 indexes[] = { 3, 0, 2, 2, 0, 1 };
IndexBufferPtr ib_ptr = GNEW(IndexBuffer);
CHECK(ib_ptr);
{
GDataPtr id_ptr = GNEW(GData);
CHECK(id_ptr);
id_ptr->Size(3*sizeof(U32) + sizeof(indexes));
U8*data_ptr = (U8*)id_ptr->Ptr();
*(U32*)data_ptr = MAKEFOURCC('G','I','B','O');
data_ptr += sizeof(U32);
*(U32*)data_ptr = sizeof(indexes)/sizeof(U16);
data_ptr += sizeof(U32);
*(U32*)data_ptr = sizeof(U16);
data_ptr += sizeof(U32);
::memcpy(data_ptr, &indexes[0], sizeof(indexes));
data_ptr += sizeof(indexes);
ib_ptr->Load(id_ptr.Ptr());
}
mQuadPtr->SetIndexBuffer(ib_ptr.Ptr());
// build the bounding box
BoundingBox box;
box.set(MAX_F32,MAX_F32,MAX_F32,MIN_F32,MIN_F32,MIN_F32);
for(U32 i = 0; i < sizeof(vertexes)/sizeof(DVTN); i++)box.expand(vertexes[i].point);
mQuadPtr->SetBox(box);
UNGUARD;
}
示例13: eventFilter
//=====================================================================
bool MouseBoxZoomer::eventFilter(QObject *widget, QEvent *e) {
GlMainWidget *glw = static_cast<GlMainWidget *>(widget);
GlGraphInputData *inputData = glw->getScene()->getGlGraphComposite()->getInputData();
if (e->type() == QEvent::MouseButtonPress) {
QMouseEvent * qMouseEv = static_cast<QMouseEvent *>(e);
if (qMouseEv->buttons() == mButton &&
(kModifier == Qt::NoModifier ||
qMouseEv->modifiers() & kModifier)) {
if (!started) {
x = qMouseEv->x();
y = glw->height() - qMouseEv->y();
w = 0;
h = 0;
started = true;
graph = inputData->getGraph();
}
else {
if (inputData->getGraph() != graph) {
graph = NULL;
started = false;
}
}
return true;
}
if (qMouseEv->buttons()==Qt::MidButton) {
started = false;
glw->redraw();
return true;
}
return false;
}
if (e->type() == QEvent::MouseMove) {
QMouseEvent * qMouseEv = static_cast<QMouseEvent *>(e);
if ((qMouseEv->buttons() & mButton) &&
(kModifier == Qt::NoModifier ||
qMouseEv->modifiers() & kModifier)) {
if (inputData->getGraph() != graph) {
graph = NULL;
started = false;
}
if (started) {
if ((qMouseEv->x() > 0) && (qMouseEv->x() < glw->width()))
w = qMouseEv->x() - x;
if ((qMouseEv->y() > 0) && (qMouseEv->y() < glw->height()))
h = y - (glw->height() - qMouseEv->y());
glw->redraw();
return true;
}
}
}
if (e->type() == QEvent::MouseButtonDblClick) {
GlBoundingBoxSceneVisitor bbVisitor(inputData);
glw->getScene()->getLayer("Main")->acceptVisitor(&bbVisitor);
QtGlSceneZoomAndPanAnimator zoomAnPan(glw, bbVisitor.getBoundingBox());
zoomAnPan.animateZoomAndPan();
return true;
}
if (e->type() == QEvent::MouseButtonRelease) {
QMouseEvent * qMouseEv = static_cast<QMouseEvent *>(e);
if ((qMouseEv->button() == mButton &&
(kModifier == Qt::NoModifier ||
qMouseEv->modifiers() & kModifier))) {
if (inputData->getGraph() != graph) {
graph = NULL;
started = false;
}
if (started) {
started = false;
if(!(w==0 && h==0)) {
int width = glw->width();
int height = glw->height();
Coord bbMin(width-x, height - y+h);
Coord bbMax(width-(x+w), height - y);
if (abs(bbMax[0] - bbMin[0]) > 1 && abs(bbMax[1] - bbMin[1]) > 1) {
BoundingBox sceneBB;
sceneBB.expand(glw->getScene()->getGraphCamera().viewportTo3DWorld(glw->screenToViewport(bbMin)));
sceneBB.expand(glw->getScene()->getGraphCamera().viewportTo3DWorld(glw->screenToViewport(bbMax)));
QtGlSceneZoomAndPanAnimator zoomAnPan(glw, sceneBB);
zoomAnPan.animateZoomAndPan();
//.........这里部分代码省略.........