void Model::modifyLastAdded(QVector<QVector3D> &guidePoints) { if (guidePoints.size() < 2 || activeNode == nullptr) return; Structure::Curve* curve = dynamic_cast<Structure::Curve*>(activeNode); Structure::Sheet* sheet = dynamic_cast<Structure::Sheet*>(activeNode); auto fp = guidePoints.takeFirst(); Vector3 axis(fp.x(),fp.y(),fp.z()); int skipAxis = -1; if (axis.isApprox(-Vector3::UnitX())) skipAxis = 0; if (axis.isApprox(-Vector3::UnitY())) skipAxis = 1; if (axis.isApprox(Vector3::UnitZ())) skipAxis = 2; // Smooth curve guidePoints = GeometryHelper::smooth(GeometryHelper::uniformResampleCount(guidePoints, 20), 5); // Convert to Vector3 Array1D_Vector3 gpoint; for(auto p : guidePoints) gpoint.push_back(Vector3(p[0],p[1],p[2])); if(curve) { auto oldPoints = curve->controlPoints(); auto newPoints = oldPoints; for(size_t i = 0; i < oldPoints.size(); i++){ for(int j = 0; j < 3; j++){ if(j == skipAxis) newPoints[i][j] = oldPoints[i][j]; else newPoints[i][j] = gpoint[i][j]; } } curve->setControlPoints(newPoints); } if(sheet) { auto oldPoints = sheet->controlPoints(); auto newPoints = oldPoints; Vector3 centroid = sheet->position(Eigen::Vector4d(0.5, 0.5, 0, 0)); Vector3 delta = gpoint.front() - centroid; for(size_t i = 0; i < oldPoints.size(); i++){ for (int j = 0; j < 3; j++){ if (j == skipAxis) continue; newPoints[i][j] += delta[j]; } } sheet->setControlPoints(newPoints); sheet->surface.quads.clear(); } generateSurface(); }
void DeformationPath::badMorphing() { for(double t = 0; t <= 1.0; t += scheduler->timeStep) { // Current nodes geometry QMap<Structure::Node*, Array1D_Vector3> startGeometry; for(auto n : scheduler->activeGraph->nodes) { if(n->property["taskTypeReal"].toInt() == Task::GROW) { Array1D_Vector3 pnts = n->controlPoints(); Vector3 p = pnts.front(); Array1D_Vector3 newpnts(pnts.size(), p); for(auto & p: newpnts) p += Eigen::Vector3d(starlab::uniformRand(), starlab::uniformRand(), starlab::uniformRand()) * 1e-5; n->setControlPoints(newpnts); } if(n->property["taskTypeReal"].toInt() == Task::SHRINK) { auto tn = scheduler->targetGraph->getNode( n->property["correspond"].toString() ); Array1D_Vector3 pnts = tn->controlPoints(); Vector3 p = pnts[pnts.size() / 2]; Array1D_Vector3 newpnts(pnts.size(), p); for(auto & p: newpnts) p += Eigen::Vector3d(starlab::uniformRand(), starlab::uniformRand(), starlab::uniformRand()) * 1e-5; tn->setControlPoints(newpnts); } startGeometry[n] = n->controlPoints(); } // Morph nodes for(auto n : scheduler->activeGraph->nodes) { auto tn = scheduler->targetGraph->getNode( n->property["correspond"].toString() ); if(!tn) continue; Array1D_Vector3 finalGeometry = tn->controlPoints(); Array1D_Vector3 newGeometry; for(int i = 0; i < (int) finalGeometry.size(); i++) newGeometry.push_back( AlphaBlend(t, startGeometry[n][i], Vector3(finalGeometry[i])) ); n->setControlPoints( newGeometry ); n->property["t"].setValue( t ); if(t > 0.5 && n->property["taskTypeReal"].toInt() == Task::SHRINK) n->property["shrunk"].setValue( true ); } scheduler->allGraphs.push_back( new Structure::Graph( *scheduler->activeGraph ) ); } property["progressDone"] = true; }