void UBGraphicsDelegateFrame::mousePressEvent(QGraphicsSceneMouseEvent *event) { mDelegate->startUndoStep(); mStartingPoint = event->scenePos(); initializeTransform(); mScaleX = 1; mScaleY = 1; mTranslateX = 0; mTranslateY = 0; mAngleOffset = 0; mInitialTransform = buildTransform(); mOriginalSize = delegated()->boundingRect().size(); mCurrentTool = toolFromPos(event->pos()); setCursorFromAngle(QString::number((int)mAngle % 360)); event->accept(); if (moving()) prepareFramesToMove(getLinkedFrames()); }
void MapBuilder<ImgType,ImgProviderType,ImgMatcherType>::buildMap(string output_prefix){ map<size_t,map<size_t,Rat>> transformMatrix; map<size_t,vector<size_t>> adjacency; double db_size = db.size(); for(size_t i = 0; i < db.size(); ++i){ ImgProviderType ndb; newDB(db[i],ndb); NearImages r = matchImage(db[i],ndb); buildTransform(transformMatrix,adjacency,db[i],r); cout << "\r" << ((i/db_size)*100) << "% " << flush; } cout << endl; writeToFile(output_prefix,transformMatrix,adjacency); }
int world_testCollision(float boundingBox[3]) { float triangle[3][3] = {{0,0,0},{0,0,0},{0,0,0}}; int i, j, k; vect_t **triPtr = triangleList, *tri; vect4_t q; // Create camera-rotation quaternion buildTransform(q); for (i = 0; i < numTriangles; i++, triPtr++) { // Copy triangle into correct format // and translate by camera position tri = *triPtr; for (j = 0; j < 3; j++) for (k = 0; k < 3; k++) triangle[j][k] = tri[k + 3*j] - camera.position[k]; // Apply camera rotation to each vertex for (k = 0; k < 3; k++) transform(triangle[k], q); // Test for collision if (doesCollide(boundingBox, triangle)) { return 1; } } return 0; }
void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if (None == mCurrentTool) return; QLineF move = QLineF(mStartingPoint, event->scenePos()); qreal moveX = move.length() * cos((move.angle() - mAngle) * PI / 180); qreal moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180); qreal width = delegated()->boundingRect().width() * mTotalScaleX; qreal height = delegated()->boundingRect().height() * mTotalScaleY; if (mOperationMode == Scaling) { if(!rotating()) { mTranslateX = moveX; // Perform the resize if (resizingBottomRight()) { // ----------------------------------------------------- // ! We want to keep the aspect ratio with this resize ! // ----------------------------------------------------- qreal scaleX; qreal scaleY; if(!mMirrorX) { scaleX = (width + moveX) / width; } else { scaleX = (width - moveX) / width; } if(!mMirrorY) { scaleY = (height + moveY) / height; } else { scaleY = (height - moveY) / height; } qreal scaleFactor = (scaleX + scaleY) / 2; // Do not allow resizing of image size under frame size if (canResizeBottomRight(width, height, scaleFactor)) { if (mRespectRatio) { mScaleX = scaleFactor; mScaleY = scaleFactor; } else { mScaleX = scaleX; mScaleY = scaleY; } } } else if (resizingLeft() || resizingRight()) { if(width != 0) { qreal scaleX = 0.0; if(resizingLeft()) { scaleX = (width - moveX) / width; } else if(resizingRight()) { scaleX = (width + moveX) / width; } if(mDelegate->isFlippable() && qAbs(scaleX) != 0) { if((qAbs(width * scaleX)) < 2*mFrameWidth) { bool negative = (scaleX < 0)?true:false; if(negative) { if(mMirrorX) scaleX = 2*mFrameWidth/width; else scaleX = -2*mFrameWidth/width; } else { scaleX = -1; mFlippedX = !mFlippedX; } } mScaleX = scaleX; } else if (scaleX > 1 || (width * scaleX) > 2 * mFrameWidth) { mScaleX = scaleX; if(resizingLeft()) { mTranslateX = moveX; } } } } else if(resizingTop() || resizingBottom()) { if(height != 0) { qreal scaleY = 0.0; if(resizingTop()) { scaleY = (height - moveY) / height; } else if(resizingBottom()) { scaleY = (height + moveY) / height; } if(mDelegate->isFlippable() && qAbs(scaleY) != 0) { if((qAbs(height * scaleY)) < 2*mFrameWidth) { bool negative = (scaleY < 0)?true:false; if(negative) { if(mMirrorY) scaleY = 2*mFrameWidth/width; else scaleY = -2*mFrameWidth/width; } else { scaleY = -1; mFlippedY = !mFlippedY; } } mScaleY = scaleY; } else if (scaleY > 1 || (height * scaleY) > 2 * mFrameWidth) { mScaleY = scaleY; if(resizingTop()) { mTranslateY = moveY; } } } } } } if (rotating()) { mTranslateX = 0; mTranslateY = 0; QLineF startLine(sceneBoundingRect().center(), event->lastScenePos()); QLineF currentLine(sceneBoundingRect().center(), event->scenePos()); mAngle += startLine.angleTo(currentLine); if ((int)mAngle % 45 >= 45 - mAngleTolerance || (int)mAngle % 45 <= mAngleTolerance) { mAngle = qRound(mAngle / 45) * 45; mAngleOffset += startLine.angleTo(currentLine); if ((int)mAngleOffset % 360 > mAngleTolerance && (int)mAngleOffset % 360 < 360 - mAngleTolerance) { mAngle += mAngleOffset; mAngleOffset = 0; } } else if ((int)mAngle % 30 >= 30 - mAngleTolerance || (int)mAngle % 30 <= mAngleTolerance) { mAngle = qRound(mAngle / 30) * 30; mAngleOffset += startLine.angleTo(currentLine); if ((int)mAngleOffset % 360 > mAngleTolerance && (int)mAngleOffset % 360 < 360 - mAngleTolerance) { mAngle += mAngleOffset; mAngleOffset = 0; } } setCursorFromAngle(QString::number((int)mAngle % 360)); } else if (moving()) { mTranslateX = move.dx(); mTranslateY = move.dy(); moveLinkedItems(move); } if (mOperationMode == Scaling || moving() || rotating()) { QTransform tr = buildTransform(); if (resizingRight() || resizingBottom() || resizingBottomRight()) { QPointF ref; // we just detects coordinates of corner before and after scaling and then moves object at diff between them. if (resizingBottomRight() && (mMirrorX || mMirrorY)) { if (mFlippedX && !mMirrorX && mFlippedY)// && !mMirrorY) { mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).x() - tr.map(delegated()->boundingRect().bottomLeft()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).y() - tr.map(delegated()->boundingRect().bottomLeft()).y(); } else if ((mFlippedX || mMirrorX) && (mFlippedY || mMirrorY)) { mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomRight()).x() - tr.map(delegated()->boundingRect().bottomRight()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomRight()).y() - tr.map(delegated()->boundingRect().bottomRight()).y(); } else if (mFlippedX || mMirrorX) { mTranslateX += mInitialTransform.map(delegated()->boundingRect().topRight()).x() - tr.map(delegated()->boundingRect().topRight()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().topRight()).y() - tr.map(delegated()->boundingRect().topRight()).y(); } else if (mFlippedY || mMirrorY) { mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).x() - tr.map(delegated()->boundingRect().bottomLeft()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).y() - tr.map(delegated()->boundingRect().bottomLeft()).y(); } else { mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomRight()).x() - tr.map(delegated()->boundingRect().bottomRight()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomRight()).y() - tr.map(delegated()->boundingRect().bottomRight()).y(); } } else { mTranslateX += mInitialTransform.map(delegated()->boundingRect().topLeft()).x() - tr.map(delegated()->boundingRect().topLeft()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().topLeft()).y() - tr.map(delegated()->boundingRect().topLeft()).y(); } } else if (resizingTop() || resizingLeft()) { QPointF bottomRight = tr.map(delegated()->boundingRect().bottomRight()); QPointF fixedPoint = mInitialTransform.map(delegated()->boundingRect().bottomRight()); mTranslateX += fixedPoint.x() - bottomRight.x(); mTranslateY += fixedPoint.y() - bottomRight.y(); } delegated()->setTransform(buildTransform()); } else // resizing/resizing horizontally { if (resizingBottomRight()) { static QSizeF incV = QSizeF(); static QSizeF incH = QSizeF(); if (mMirrorX && mMirrorY) mCurrentTool = ResizeTop; else mCurrentTool = ResizeBottom; incV = resizeDelegate(moveX, moveY); mOriginalSize += incV; if (mMirrorX && mMirrorY) mCurrentTool = ResizeLeft; else mCurrentTool = ResizeRight; move = QLineF(event->lastScenePos(), event->scenePos()); moveX = move.length() * cos((move.angle() - mAngle) * PI / 180); moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180); mFixedPoint = getFixedPointFromPos(); incH = resizeDelegate(moveX, moveY); mOriginalSize -= incV; mOriginalSize += incH; mCurrentTool = ResizeBottomRight; } else resizeDelegate(moveX, moveY); } event->accept(); }
int SOP_PrimGroupCentroid::bindToCentroids(fpreal t, int mode, int method) { int behavior; exint int_value; const GA_PrimitiveGroup *group; GA_PrimitiveGroup *all_prims, *temp_group; GA_Range pr_range; GA_ROAttributeRef attr_gah, primattr_gah; GA_ROHandleI class_h; GA_ROHandleS str_h; const GU_Detail *input_geo; UT_Matrix4 mat; UT_String attr_name, pattern, str_value; UT_Vector3 pos; // Get the second input geometry as read only. GU_DetailHandleAutoReadLock gdl(inputGeoHandle(1)); input_geo = gdl.getGdp(); // Get the unmatched geometry behavior. behavior = BEHAVIOR(t); // Create a new attribute reference map. GA_AttributeRefMap hmap(*gdp, input_geo); // Get the attribute selection string. BIND(pattern, t); // If we have a pattern, try to build the ref map. if (pattern.length() > 0) buildRefMap(hmap, pattern, gdp, input_geo, mode, GA_ATTRIB_POINT); // The list of GA_Primitives in the input geometry. const GA_PrimitiveList &prim_list = gdp->getPrimitiveList(); // Create a temporary primitive group so we can keep track of all the // primitives we have modified. all_prims = createAdhocPrimGroup(*gdp, "allprims"); // Determine which attribute we need from the points, based on the mode. switch (mode) { case 0: attr_name = "group"; break; case 1: attr_name = "name"; break; case 2: attr_name = "class"; break; default: addError(SOP_MESSAGE, "Invalid mode setting"); return 1; } // Find the attribute. attr_gah = input_geo->findPointAttribute(attr_name); // If there is no attribute, add an error message and quit. if (attr_gah.isInvalid()) { addError(SOP_ATTRIBUTE_INVALID, attr_name); return 1; } // If not using groups, we need to check if the matching primitive // attribute exists on the geometry. if (mode != 0) { // Try to find the attribute. primattr_gah = gdp->findPrimitiveAttribute(attr_name); // If there is no attribute, add an error message and quit. if (primattr_gah.isInvalid()) { addError(SOP_ATTRIBUTE_INVALID, attr_name); return 1; } } // 'class' uses the int handle. if (mode == 2) class_h.bind(attr_gah.getAttribute()); // Groups and 'name' use the string handle. else str_h.bind(attr_gah.getAttribute()); for (GA_Iterator it(input_geo->getPointRange()); !it.atEnd(); ++it) { if (mode == 0) { // Get the unique string value. str_value = str_h.get(*it); // Find the group on the geometry to bind. group = gdp->findPrimitiveGroup(str_value); // Ignore non-existent groups. if (!group) continue; // Skip emptry groups. if (group->isEmpty()) continue; // The primtives in the group. pr_range = gdp->getPrimitiveRange(group); } else { if (mode == 1) { // Get the unique string value. str_value = str_h.get(*it); // Get the prims with that string value. pr_range = gdp->getRangeByValue(primattr_gah, str_value); } else { // Get the unique integer value. int_value = class_h.get(*it); // Get the prims with that integery value. pr_range = gdp->getRangeByValue(primattr_gah, int_value); } // Create an adhoc group. temp_group = createAdhocPrimGroup(*gdp); temp_group->addRange(pr_range); } // Add the primitives in the range to the groups. all_prims->addRange(pr_range); // Bounding Box if (method == 1) { // Calculate the bouding box center for this range. boundingBox(gdp, pr_range, prim_list, pos); } // Center of Mass else if (method == 2) { // Calculate the center of mass for this attribute value. centerOfMass(pr_range, prim_list, pos); } // Barycenter else { // Calculate the barycenter for this attribute value. baryCenter(gdp, pr_range, prim_list, pos); } // Build the transform from the point information. buildTransform(mat, input_geo, pos, *it); // Transform the geometry from the centroid. if (mode == 0) gdp->transform(mat, group); else gdp->transform(mat, temp_group); // Copy any necessary attributes from the incoming points to the // geometry. if (hmap.entries()) { for (GA_Iterator pr_it(pr_range); !pr_it.atEnd(); ++pr_it) { hmap.copyValue(GA_ATTRIB_PRIMITIVE, *pr_it, GA_ATTRIB_POINT, *it); } } } // We want to destroy prims that didn't have a matching name/group. if (behavior) { // Flip the membership of all the prims that we did see. all_prims->toggleEntries(); // Destroy the ones that we didn't. gdp->deletePrimitives(*all_prims, true); } return 0; }