void EraserWidget::continousRemoveSlot() { Transform3D rMd = mVisualizationService->getGroup(0)->getOptions().mPickerGlyph->get_rMd(); //Transform3D rMd = mVisualizationService->getViewGroupDatas().front()->getData()->getOptions().mPickerGlyph->get_rMd(); Vector3D c(mSphere->GetCenter()); c = rMd.coord(c); double r = mSphere->GetRadius(); // optimization: dont remove if idle if (similar(mPreviousCenter, c) && similar(mPreviousRadius, r)) return; this->removeSlot(); }
void VideoGraphics::updatePlaneSourceBounds() { // set the planesource where we have no ProbeDefinition. // TODO dont do this when planesource is not part of pipeline. DoubleBoundingBox3D bounds(mDataRedirecter->GetOutput()->GetBounds()); if (!similar(bounds.range()[0], 0.0) || !similar(bounds.range()[1], 0.0)) { mPlaneSource->SetOrigin(bounds.corner(0,0,0).begin()); mPlaneSource->SetPoint1(bounds.corner(1,0,0).begin()); mPlaneSource->SetPoint2(bounds.corner(0,1,0).begin()); mPlaneSource->GetOutput()->GetPointData()->Modified(); mPlaneSource->GetOutput()->Modified(); } }
void Image::setCroppingBox(const DoubleBoundingBox3D& bb_d) { if (similar(mCroppingBox_d, bb_d)) return; mCroppingBox_d = bb_d; emit cropBoxChanged(); }
void CameraControl::setStandard3DViewActionSlot() { QAction* action = dynamic_cast<QAction*> (sender()); if (!action) return; Vector3D viewDirection = Vector3D::fromString(action->data().toString()); vtkRendererPtr renderer = this->getRenderer(); if (!renderer) return; vtkCameraPtr camera = this->getCamera(); renderer->ResetCamera(); Vector3D focus(camera->GetFocalPoint()); Vector3D pos = focus - 500 * viewDirection; Vector3D vup(0, 0, 1); //Vector3D dir = (focus-direction).normal(); Vector3D left = cross(vup, viewDirection); if (similar(left.length(), 0.0)) left = Vector3D(1, 0, 0); vup = cross(viewDirection, left).normal(); camera->SetPosition(pos.begin()); camera->SetViewUp(vup.begin()); renderer->ResetCamera(); // let vtk do the zooming base work camera->Dolly(1.5); // zoom in a bit more than the default vtk value renderer->ResetCameraClippingRange(); }
void CmSaliencyRC::GetHC(CMat &binColor3f, CMat &colorNums1i, Mat &_colorSal) { Mat weight1f; normalize(colorNums1i, weight1f, 1, 0, NORM_L1, CV_32F); int binN = binColor3f.cols; _colorSal = Mat::zeros(1, binN, CV_32F); float* colorSal = (float*)(_colorSal.data); vector<vector<CostfIdx>> similar(binN); // Similar color: how similar and their index Vec3f* color = (Vec3f*)(binColor3f.data); float *w = (float*)(weight1f.data); for (int i = 0; i < binN; i++){ vector<CostfIdx> &similari = similar[i]; similari.push_back(make_pair(0.f, i)); for (int j = 0; j < binN; j++){ if (i == j) continue; float dij = vecDist<float, 3>(color[i], color[j]); similari.push_back(make_pair(dij, j)); colorSal[i] += w[j] * dij; } sort(similari.begin(), similari.end()); } SmoothSaliency(_colorSal, 0.25f, similar); }
void CameraData::parseXml(QDomNode dataNode) { Vector3D position = Vector3D::fromString(dataNode.namedItem("position").toElement().text()); Vector3D focalPoint = Vector3D::fromString(dataNode.namedItem("focalPoint").toElement().text()); Vector3D viewUp = Vector3D::fromString(dataNode.namedItem("viewUp").toElement().text()); double nearClip = dataNode.namedItem("nearClip").toElement().text().toDouble(); double farClip = dataNode.namedItem("farClip").toElement().text().toDouble(); double parallelScale = dataNode.namedItem("parallelScale").toElement().text().toDouble(); if (similar(viewUp.length(), 0.0)) return; // ignore reading if undefined data double LARGE_NUMBER = 1.0E6; // corresponding to a distance of 1km - unphysical for human-sized data if ((position-focalPoint).length() > LARGE_NUMBER) return; if (focalPoint.length() > LARGE_NUMBER) return; if (fabs(parallelScale) > LARGE_NUMBER) return; this->getCamera(); mCamera->SetClippingRange(nearClip, farClip); mCamera->SetPosition(position.begin()); mCamera->SetFocalPoint(focalPoint.begin()); mCamera->ComputeViewPlaneNormal(); mCamera->SetViewUp(viewUp.begin()); mCamera->SetParallelScale(parallelScale); }
void Saliency::GetHC(const Mat &binColor3f, const Mat &weight1f, Mat &_colorSal) { int binN = binColor3f.cols; _colorSal = Mat::zeros(1, binN, CV_32F); float* colorSal = (float*)(_colorSal.data); vector<vector<CostfIdx>> similar(binN); // Similar color: how similar and their index Vec3f* color = (Vec3f*)(binColor3f.data); float *w = (float*)(weight1f.data); for (int i = 0; i < binN; i++) { vector<CostfIdx> &similari = similar[i]; similari.push_back(make_pair(0.f, i)); for (int j = 0; j < binN; j++) { if (i == j) continue; float dij = vecDist3<float>(color[i], color[j]); similari.push_back(make_pair(dij, j)); colorSal[i] += w[j] * dij; } sort(similari.begin(), similari.end()); } SmoothSaliency(binColor3f, _colorSal, 4.0f, similar); }
void CustomMetric::updateTexture(MeshPtr model, Transform3D rMrr) { if (!model) return; if (!this->getTextureFollowTool() || !model->hasTexture()) return; // special case: // Project tool position down to the model, then set that position as // the texture x pos. Transform3D rMt = mSpaceProvider->getActiveToolTipTransform(CoordinateSystem::reference()); Transform3D rMd = rMrr * model->get_rMd(); Vector3D t_r = rMt.coord(Vector3D::Zero()); Vector3D td_r = rMt.vector(Vector3D::UnitZ()); DoubleBoundingBox3D bb_d = model->boundingBox(); Vector3D bl = bb_d.bottomLeft(); Vector3D tr = bb_d.topRight(); Vector3D c = (bl+tr)/2; Vector3D x_min_r(c[0], bl[1], c[2]); Vector3D x_max_r(c[0], tr[1], c[2]); x_min_r = rMd.coord(x_min_r); x_max_r = rMd.coord(x_max_r); double t_x = dot(t_r, td_r); double bbmin_x = dot(x_min_r, td_r); double bbmax_x = dot(x_max_r, td_r); double range = bbmax_x-bbmin_x; if (similar(range, 0.0)) range = 1.0E-6; double s = (t_x-bbmin_x)/range; model->getTextureData().getPositionY()->setValue(s); }
/** * This is called every frame. We use this as an oportunity to RedrawWindow() * the control if the user has moved. */ /*afx_msg*/ void ChunkWatchControl::OnUpdateControl() { // Don't update to frequently. if (lastUpdateTime_ != 0) { uint64 now = timestamp(); if ((now - lastUpdateTime_)/(double)stampsPerSecond() < UPDATE_DELTA) { return; } } lastUpdateTime_ = timestamp(); Matrix view = WorldEditorCamera::instance().currentCamera().view(); view.invert(); Chunk *workingChunk = WorldManager::instance().workingChunk(); if ( !similar(view, drawPos_, MATRICES_COMP_EPSILON) || workingChunk != lastWorkingChunk_ ) { RedrawWindow(); } }
void ToolImpl::setTooltipOffset(double val) { if (similar(val, mTooltipOffset)) return; mTooltipOffset = val; emit tooltipOffset(mTooltipOffset); }
std::vector<std::vector<T>> group(std::vector<T> v, F similar) { UnionFind uf(v.size()); for (size_t i = 0; i < v.size(); ++i) { for (size_t j = i + 1; j < v.size(); ++j) { if (similar(v[i], v[j])) { uf.join(i, j); } } } std::vector<int> idxmap(v.size(), -1); std::vector<std::vector<T>> vs; for (size_t i = 0; i < v.size(); ++i) { size_t set = uf.find(i); int group = idxmap[set]; if (group < 0) { idxmap[set] = vs.size(); vs.emplace_back(1, v[i]); } else { vs[group].push_back(v[i]); } } return vs; }
void IgstkTool::processReceivedTransformResult(igstk::CoordinateSystemTransformToResult result) { if (!this->validReferenceForResult(result)) return; // emit even if not visible: need error metadata igstk::NDITracker::TrackingSampleInfo sampleInfo = this->getSampleInfo(); // ignore duplicate positions if (similar(mLatestEmittedTimestamp, sampleInfo.m_TimeStamp,1.0E-3)) { return; } mLatestEmittedTimestamp = sampleInfo.m_TimeStamp; QDomDocument doc; QDomElement root = doc.createElement("info"); doc.appendChild(root); sampleInfo2xml(sampleInfo, root); ToolPositionMetadata metadata; metadata.mData = doc.toString(); igstk::Transform transform = result.GetTransform(); Transform3D prMt = igstk2Transform3D(transform); double timestamp = transform.GetStartTime(); emit toolTransformAndTimestamp(prMt, timestamp, metadata); }
void SliceProxy::changed() { SlicePlane plane = mCutplane->getPlane(); if (similar(plane, mLastEmittedSlicePlane)) return; mLastEmittedSlicePlane = plane; emit transformChanged(get_sMr()); }
void ProbeImpl::setSoundSpeedCompensationFactor(double factor) { if(similar(mSoundSpeedCompensationFactor, factor)) return; mSoundSpeedCompensationFactor = factor; for (std::map<QString, ProbeDefinition>::iterator iter=mProbeData.begin(); iter!=mProbeData.end(); ++iter) iter->second.applySoundSpeedCompensationFactor(mSoundSpeedCompensationFactor); emit sectorChanged(); }
bool DoublePropertyShadingDiffuse::setValue(double val) { if (!mImage) return false; if (similar(val, mImage->getShadingDiffuse())) return false; mImage->setShadingDiffuse(val); return true; }
bool DoublePropertyShadingSpecularPower::setValue(double val) { if (!mImage) return false; if (similar(val, mImage->getShadingSpecularPower())) return false; mImage->setShadingSpecularPower(val); return true; }
Vector3D DonutMetric::getDirection() { std::vector<Vector3D> coords = mArguments->getRefCoords(); if (coords.size()<2) return Vector3D::UnitZ(); Vector3D diff = (coords[1]-coords[0]); if (similar(diff.length(), 0.0)) return Vector3D(0,1,0); return diff.normal(); }
// methods for defining and storing a cropping box. Image does not use these data, this is up to the mapper void Image::setCropping(bool on) { if (mUseCropping == on) return; mUseCropping = on; if (similar(mCroppingBox_d, this->getInitialBoundingBox())) mCroppingBox_d = this->boundingBox(); emit cropBoxChanged(); }
void DecomposedTransform3D::reset(Transform3D m) { DecomposedTransform3D input(m); bool eqPos = similar(input.mPos, mPos); if (!eqPos) { mPos = input.mPos; } input.mPos = mPos; bool eqRot = similar(input.getMatrix(), this->getMatrix()); // only reset angles if the input rotation matrix is different from the current. if (!eqRot) { mAngle = input.mAngle; m_R = input.m_R; } }
void CmSaliencyRC::SmoothByHist(CMat &img3f, Mat &sal1f, float delta) { //imshow("Before", sal1f); imshow("Src", img3f); // Quantize colors CV_Assert(img3f.size() == sal1f.size() && img3f.type() == CV_32FC3 && sal1f.type() == CV_32FC1); Mat idx1i, binColor3f, colorNums1i; int binN = Quantize(img3f, idx1i, binColor3f, colorNums1i); //CmShow::HistBins(binColor3f, colorNums1i, "Frequency"); // Get initial color saliency Mat _colorSal = Mat::zeros(1, binN, CV_64FC1); int rows = img3f.rows, cols = img3f.cols;{ double* colorSal = (double*)_colorSal.data; if (img3f.isContinuous() && sal1f.isContinuous()) cols *= img3f.rows, rows = 1; for (int y = 0; y < rows; y++){ const int* idx = idx1i.ptr<int>(y); const float* initialS = sal1f.ptr<float>(y); for (int x = 0; x < cols; x++) colorSal[idx[x]] += initialS[x]; } const int *colorNum = (int*)(colorNums1i.data); for (int i = 0; i < binN; i++) colorSal[i] /= colorNum[i]; normalize(_colorSal, _colorSal, 0, 1, NORM_MINMAX, CV_32F); } // Find similar colors & Smooth saliency value for color bins vector<vector<CostfIdx>> similar(binN); // Similar color: how similar and their index Vec3f* color = (Vec3f*)(binColor3f.data); cvtColor(binColor3f, binColor3f, CV_BGR2Lab); for (int i = 0; i < binN; i++){ vector<CostfIdx> &similari = similar[i]; similari.push_back(make_pair(0.f, i)); for (int j = 0; j < binN; j++) if (i != j) similari.push_back(make_pair(vecDist<float, 3>(color[i], color[j]), j)); sort(similari.begin(), similari.end()); } cvtColor(binColor3f, binColor3f, CV_Lab2BGR); //CmShow::HistBins(binColor3f, _colorSal, "BeforeSmooth", true); SmoothSaliency(colorNums1i, _colorSal, delta, similar); //CmShow::HistBins(binColor3f, _colorSal, "AfterSmooth", true); // Reassign pixel saliency values float* colorSal = (float*)(_colorSal.data); for (int y = 0; y < rows; y++){ const int* idx = idx1i.ptr<int>(y); float* resSal = sal1f.ptr<float>(y); for (int x = 0; x < cols; x++) resSal[x] = colorSal[idx[x]]; } //imshow("After", sal1f); //waitKey(0); }
void DecomposedTransform3D::setAngles(Vector3D xyz) { // std::cout << "setAngles " << xyz << std::endl; if (!similar(xyz[0], mAngle[0])) { m_R = m_R * createTransformRotateX(xyz[0] - mAngle[0]); mAngle[0] = xyz[0]; } if (!similar(xyz[1], mAngle[1])) { m_R = m_R * createTransformRotateY(xyz[1] - mAngle[1]); mAngle[1] = xyz[1]; } if (!similar(xyz[2], mAngle[2])) { m_R = m_R * createTransformRotateZ(xyz[2] - mAngle[2]); mAngle[2] = xyz[2]; } }
void ImageParameters::alignSpacingKeepDim(Eigen::Array3d bounds) { for (unsigned i = 0; i < 3; ++i) { //Set spacing to 1 if one of the axes is degenerated if((mDim[i] == 1) && similar(bounds[i], 0.0)) mSpacing[i] = 1; else mSpacing[i] = bounds[i] / double(mDim[i]-1); } }
/**We need this here, even if it belongs in singlelayout. * Reason: must call setcamera after last change of size of plane actor. * TODO fix it. */ void VideoFixedPlaneRep::setCamera() { if (!mRenderer) return; mViewportListener->stopListen(); vtkCamera* camera = mRenderer->GetActiveCamera(); camera->ParallelProjectionOn(); mRenderer->ResetCamera(); DoubleBoundingBox3D bounds(mRTGraphics->getActor()->GetBounds()); if (similar(bounds.range()[0], 0.0) || similar(bounds.range()[1], 0.0)) return; double* vpRange = mRenderer->GetAspect(); double vw = vpRange[0]; double vh = vpRange[1]; double w = bounds.range()[0]; double h = bounds.range()[1]; double scale = 1; double w_vp = vh * (w/h); // width of image in viewport space if (w_vp > vw) // if image too wide: reduce scale scale = w_vp/vw; //Set camera position and focus so that it looks at the video stream center double position[3]; camera->GetPosition(position); position[0] = bounds.center()[0]; position[1] = bounds.center()[1]; camera->SetPosition(position); camera->GetFocalPoint(position); position[0] = bounds.center()[0]; position[1] = bounds.center()[1]; camera->SetFocalPoint(position); camera->SetParallelScale(h/2*scale*1.01); // exactly fill the viewport height mViewportListener->startListen(mRenderer); }
void Transform3DWidget::textEditChangedSlot() { bool ok = false; Transform3D M = Transform3D::fromString(mTextEdit->toPlainText(), &ok); // ignore setting if invalid matrix or no real change done (hopefully, this allows trivial editing without text reset) if (!ok) return; if (similar(M, this->getMatrixInternal())) return; this->setMatrixInternal(M); }
bool operator==(const VertexData& a, const VertexData& b) { return (similar(a.x, b.x) && similar(a.y, b.y) && similar(a.z, b.z) && similar(a.nx, b.nx) && similar(a.ny, b.ny) && similar(a.nz, b.nz) && (a.uvs == b.uvs) && (a.weights == b.weights)); }
bool TemporalCalibration::checkFrameMovementQuality(std::vector<double> pos) { int count = 0; for (unsigned i=0; i<pos.size(); ++i) if (similar(pos[i], 0)) count++; // accept if less than 20% zeros. double error = double(count)/pos.size(); if (error > 0.05) reportWarning(QString("Found %1 % zeros in frame movement").arg(error*100)); return error < 0.2; }
bool similar(const Transform3D& a, const Transform3D& b, double tol) { boost::array<double, 16> m = a.flatten(); boost::array<double, 16> n = b.flatten(); for (int j = 0; j < 16; ++j) { if (!similar(n[j], m[j], tol)) { return false; } } return true; }
void ToolImpl::set_prMt(const Transform3D& prMt, double timestamp) { if (mPositionHistory->count(timestamp)) { if (similar(mPositionHistory->find(timestamp)->second, prMt)) return; } m_prMt = prMt; // Store positions in history, but only if visible - the history has no concept of visibility if (this->getVisible()) (*mPositionHistory)[timestamp] = m_prMt; emit toolTransformAndTimestamp(m_prMt, timestamp); }
bool Vector3DProperty::setValue(const Vector3D& val) { if (similar(val, mValue)) return false; // std::cout << "set val " << " " << val << " , org=" << mValue << std::endl; mValue = val; mStore.writeValue(qstring_cast(val)); emit valueWasSet(); emit changed(); return true; }
void CGameObject::UpdateCL () { inherited::UpdateCL (); // if (!is_ai_obstacle()) // return; if (H_Parent()) return; if (similar(XFORM(),m_previous_matrix,EPS)) return; on_matrix_change (m_previous_matrix); m_previous_matrix = XFORM(); }