From 258439436fdb17c1d76733ffa70dbb666da1a20e Mon Sep 17 00:00:00 2001 From: codereader Date: Thu, 10 Dec 2020 19:19:32 +0100 Subject: [PATCH] #5382: Dispose of all the unused code --- radiantcore/patch/algorithm/General.cpp | 676 +----------------------- 1 file changed, 3 insertions(+), 673 deletions(-) diff --git a/radiantcore/patch/algorithm/General.cpp b/radiantcore/patch/algorithm/General.cpp index ab0e7daefe..96cdaf436e 100644 --- a/radiantcore/patch/algorithm/General.cpp +++ b/radiantcore/patch/algorithm/General.cpp @@ -163,274 +163,16 @@ void bulge(const cmd::ArgumentList& args) } } -// Adapter method, since the ODRadiant patches allows accessing the patch controls -// with row and col indices outside the control array bounds, with wrap around behaviour -inline PatchControl& getControl(IPatch& patch, int row, int col) -{ - if (col < 0 || col >= patch.getWidth() || row < 0 || row >= patch.getHeight()) - { - return patch.ctrlAt(row % patch.getHeight(), col % patch.getWidth()); - } - - return patch.ctrlAt(row, col); -} - -PatchNodePtr createdMergedPatch(const PatchNodePtr& patchNode1, const PatchNodePtr& patchNode2, - int sourceCol1, int sourceCol2, int sourceRow1, int sourceRow2, bool invert1, bool invert2) -{ - float s, t; - int col1, col2; - int row1, row2; - int adj1, adj2; - int in, out; - int w, h; - - auto& patch1 = patchNode1->getPatch(); - auto& patch2 = patchNode2->getPatch(); - - auto node = GlobalPatchModule().createPatch(patch1.subdivisionsFixed() ? PatchDefType::Def3 : PatchDefType::Def2); - auto newPatchNode = std::dynamic_pointer_cast(node); - auto& newPatch = newPatchNode->getPatch(); - - newPatch.setShader(patch1.getShader()); - - // Merge the patches - if (sourceCol1 >= 0) - { - // Adding width - if (sourceCol2 >= 0) - { - // From width - newPatch.setDims(patch1.getWidth() + patch2.getWidth() - 1, patch1.getHeight()); - - col1 = 0; - col2 = 1; - - adj1 = 1; - adj2 = 1; - - if (sourceCol1 != 0) - { - adj1 = -1; - col1 = patch1.getWidth() - 1; - } - - if (sourceCol2 != 0) - { - adj2 = -1; - col2 = patch2.getWidth() - 2; - } - - out = 0; - - for (w = 0; w < patch1.getWidth(); w++, col1 += adj1) - { - in = invert1 ? patch1.getHeight() - 1 : 0; - - for (h = 0; h < patch1.getHeight(); h++) - { - getControl(newPatch, h, out) = getControl(patch1, in, col1); - - in += invert1 ? -1 : 1; - } - - out++; - } - - for (w = 1; w < patch2.getWidth(); w++, col2 += adj2) - { - in = invert2 ? patch2.getHeight() - 1 : 0; - - for (h = 0; h < patch2.getHeight(); h++) - { - getControl(newPatch, h, out) = getControl(patch2, in, col2); - - in += invert2 ? -1 : 1; - } - - out++; - } - } - else - { - // From height - newPatch.setDims(patch1.getWidth() + patch2.getHeight() - 1, patch1.getHeight()); - - col1 = 0; - row2 = 1; - - adj1 = 1; - adj2 = 1; - - if (sourceCol1 != 0) - { - adj1 = -1; - col1 = patch1.getWidth() - 1; - } - - if (sourceRow2 != 0) - { - adj2 = -1; - row2 = patch2.getHeight() - 2; - } - - out = 0; - - for (w = 0; w < patch1.getWidth(); w++, col1 += adj1) - { - in = invert1 ? patch1.getHeight() - 1 : 0; - - for (h = 0; h < patch1.getHeight(); h++) - { - getControl(newPatch, h, out) = getControl(patch1, in, col1); - - in += invert1 ? -1 : 1; - } - - out++; - } - - for (h = 1; h < patch2.getHeight(); h++, row2 += adj2) - { - in = invert2 ? patch2.getWidth() - 1 : 0; - - for (w = 0; w < patch2.getWidth(); w++) - { - getControl(newPatch, w, out) = getControl(patch2, row2, in); - - in += invert2 ? -1 : 1; - } - - out++; - } - } - } - else - { - // Adding height - if (sourceRow1 >= 0) - { - // From height - newPatch.setDims(patch1.getWidth(), patch1.getHeight() + patch2.getHeight() - 1); - - row1 = 0; - row2 = 0; - - adj1 = 1; - adj2 = 1; - - if (sourceRow1 != 0) - { - adj1 = -1; - row1 = patch1.getHeight() - 1; - } - - if (sourceRow2 != 0) - { - adj2 = -1; - row2 = patch2.getHeight() - 2; - } - - out = 0; - - for (h = 0; h < patch1.getHeight(); h++, row1 += adj1) - { - in = invert1 ? patch1.getWidth() - 1 : 0; - - for (w = 0; w < patch1.getWidth(); w++) - { - getControl(newPatch, out, w) = getControl(patch1, row1, in); - - in += invert1 ? -1 : 1; - } - - out++; - } - - for (h = 1; h < patch2.getHeight(); h++, row2 += adj2) - { - in = invert2 ? patch1.getWidth() - 1 : 0; - - for (w = 0; w < patch2.getWidth(); w++) - { - getControl(newPatch, out, w) = getControl(patch2, row2, in); - - in += invert1 ? -1 : 1; - } - - out++; - } - } - else - { - // From width - newPatch.setDims(patch1.getWidth() + patch2.getHeight() - 1, patch1.getHeight()); - - row1 = 0; - col2 = 0; - - adj1 = 1; - adj2 = 1; - - if (sourceRow1 != 0) - { - adj1 = -1; - row1 = patch1.getHeight() - 1; - } - - if (sourceCol2 != 0) - { - adj2 = -1; - col2 = patch2.getWidth() - 2; - } - - out = 0; - - for (h = 0; h < patch1.getHeight(); h++, row1 += adj1) - { - in = invert1 ? patch1.getWidth() - 1 : 0; - - for (w = 0; w < patch1.getWidth(); w++) - { - getControl(newPatch, out, w) = getControl(patch1, row1, in); - - in += invert1 ? -1 : 1; - } - - out++; - } - - for (w = 1; w < patch2.getWidth(); w++, col2 += adj2) - { - in = invert2 ? patch1.getHeight() - 1 : 0; - - for (h = 0; h < patch2.getHeight(); h++) - { - getControl(newPatch, out, h) = getControl(patch2, in, col2); - - in += invert1 ? -1 : 1; - } - - out++; - } - } - } - - newPatch.controlPointsChanged(); - - return newPatchNode; -} - namespace { // Returns true if elements in the given sequences are equal -inline bool firstNItemsAreEqual(const PatchControlIterator& sequence1, const PatchControlIterator& sequence2, std::size_t num, double epsilon) +inline bool firstNItemsAreEqual(const PatchControlIterator& sequence1, + const PatchControlIterator& sequence2, std::size_t num, double epsilon) { // If the iterators are invalid from the start, return false if (!sequence1.isValid() || !sequence2.isValid()) { - rMessage() << "Sequences are not valid" << std::endl; return false; } @@ -439,16 +181,12 @@ inline bool firstNItemsAreEqual(const PatchControlIterator& sequence1, const Pat for (std::size_t n = 0; n < num && p1.isValid() && p2.isValid(); ++n, ++p1, ++p2) { - rMessage() << "P1: " << p1->vertex << ", P2: " << p2->vertex << std::endl; - if (!p1->vertex.isEqual(p2->vertex, epsilon)) { - rMessage() << "Sequences are not equal" << std::endl; return false; } } - rMessage() << "Sequences are equal" << std::endl; return true; } @@ -470,14 +208,6 @@ scene::INodePtr createdMergedPatch(const PatchNodePtr& patchNode1, const PatchNo { constexpr double WELD_EPSILON = 0.001; -#if 0 - // Algorithm ported from ODRadiant https://svn.code.sf.net/p/odblur/code/code/OverDose%20Tools/ODRadiant/Patch.cpp) rev8348 - int col, col1, col2; - int row, row1, row2; - int adj1, adj2; - bool match; -#endif - if (patchNode1->getParent() != patchNode2->getParent()) { throw cmd::ExecutionFailure(_("Patches have different parent entities, cannot weld.")); @@ -536,16 +266,13 @@ scene::INodePtr createdMergedPatch(const PatchNodePtr& patchNode1, const PatchNo continue; // length don't match } - rMessage() << "Comparing " << std::get<4>(patch1Edge) << " to " << std::get<3>(patch2Edge) << std::endl; + //rMessage() << "Comparing " << std::get<4>(patch1Edge) << " to " << std::get<3>(patch2Edge) << std::endl; if (!firstNItemsAreEqual(std::get<0>(patch1Edge), std::get<0>(patch2Edge), std::get<3>(patch1Edge), WELD_EPSILON)) { continue; } - // Found a shared edge - rMessage() << "Found a shared edge" << std::endl; - // Expand the patch dimensions std::size_t numNewRows = patch1.getHeight(); std::size_t numNewColumns = patch1.getWidth(); @@ -579,398 +306,6 @@ scene::INodePtr createdMergedPatch(const PatchNodePtr& patchNode1, const PatchNo } } -#if 0 - rMessage() << "Comparing P1FirstRow to P2FirstRow" << std::endl; - if (isEqual(patch1FirstRow, patch2FirstRow, WELD_EPSILON)) - { - auto newPatchNode = GlobalPatchModule().createPatch(patch1.subdivisionsFixed() ? PatchDefType::Def3 : PatchDefType::Def2); - auto& newPatch = std::dynamic_pointer_cast(newPatchNode)->getPatch(); - newPatch.setDims(patch1.getWidth(), patch1.getHeight() + patch2.getHeight() - 1); - - // prepend - // use rows of other patch - } - - rMessage() << "Comparing P1FirstRow to P2FirstRowReverse" << std::endl; - if (isEqual(patch1FirstRow, patch2FirstRowReverse, WELD_EPSILON)) - { - int i = 0; - } - - rMessage() << "Comparing P1FirstRow to P2LastRow" << std::endl; - if (isEqual(patch1FirstRow, patch2LastRow, WELD_EPSILON)) - { - int i = 0; - // prepend - // use rows of other patch from end - } - - rMessage() << "Comparing P1FirstRow to P2LastRowReverse" << std::endl; - if (isEqual(patch1FirstRow, patch2LastRowReverse, WELD_EPSILON)) - { - int i = 0; - } - - rMessage() << "Comparing P1LastRow to P2FirstRow" << std::endl; - if (isEqual(patch1LastRow, patch2FirstRow, WELD_EPSILON)) - { - auto sceneNode = GlobalPatchModule().createPatch(patch1.subdivisionsFixed() ? PatchDefType::Def3 : PatchDefType::Def2); - auto& newPatch = std::dynamic_pointer_cast(sceneNode)->getPatch(); - newPatch.setDims(patch1.getWidth(), patch1.getHeight() + patch2.getHeight() - 1); - - RowWisePatchIterator p1(patch1); - RowWisePatchIterator p2(patch2, 1, patch2.getWidth() - 1); // skip the first row of the second patch - RowWisePatchIterator target(newPatch); - - assignPatchControls(p1, target); - assignPatchControls(p2, target); - - newPatch.controlPointsChanged(); - - return sceneNode; - } - - rMessage() << "Comparing P1LastRow to P2FirstRowReverse" << std::endl; - if (isEqual(patch1LastRow, patch2FirstRowReverse, WELD_EPSILON)) - { - int i = 6; - } - - rMessage() << "Comparing P1LastRow to P2LastRow" << std::endl; - if (isEqual(patch1LastRow, patch2LastRow, WELD_EPSILON)) - { - int i = 0; - // append - // use rows of other patch from end - } - - rMessage() << "Comparing P1LastRow to P2LastRowReverse" << std::endl; - if (isEqual(patch1LastRow, patch2LastRowReverse, WELD_EPSILON)) - { - int i = 6; - } -#endif -#if 0 - if (patch1.getWidth() == patch2.getWidth()) - { - row1 = 0; - row2 = 0; - - while (true) - { - match = false; - - col1 = 0; - col2 = 0; - - adj1 = 0; - adj2 = 0; - - if (getControl(patch1, row1, 0).vertex.isEqual(getControl(patch2, row2, 0).vertex, WELD_EPSILON)) - {} - else if (getControl(patch1, row1, 0).vertex.isEqual(getControl(patch2, patch2.getWidth() - 1, row2).vertex, WELD_EPSILON)) - { - col2 = patch2.getWidth() - 1; - adj2 = -1; - } - else if (getControl(patch1, patch1.getWidth() - 1, row1).vertex.isEqual(getControl(patch2, patch2.getWidth() - 1, row2).vertex, WELD_EPSILON)) - { - col2 = patch2.getWidth() - 1; - adj2 = -1; - - col1 = patch1.getWidth() - 1; - adj1 = -1; - } - else if (getControl(patch1, patch1.getWidth() - 1, row1).vertex.isEqual(getControl(patch2, row2, 0).vertex, WELD_EPSILON)) - { - col1 = patch1.getWidth() - 1; - adj1 = -1; - } - else - { - adj1 = 0; - } - - if (adj1) - { - match = true; - - for (col = 0; col < patch1.getWidth(); col++, col2 += adj2, col1 += adj1) - { - if (!getControl(patch1, row1, col1).vertex.isEqual(getControl(patch2, row2, col2).vertex, WELD_EPSILON)) - { - match = false; - break; - } - } - } - - if (match) - { - rMessage() << "Welding row " << row1 << " with row " << row2 << std::endl; - - row1 = (row1 == 0) ? patch1.getHeight() - 1 : 0; - - return createdMergedPatch(patchNode1, patchNode2, -1, -1, row1, row2, (adj1 == -1), (adj2 == -1)); - } - - if (row2 == 0) - { - row2 = patch2.getHeight() - 1; - } - else if (row1 == 0) - { - row1 = patch1.getHeight() - 1; - row2 = 0; - } - else - { - break; - } - } - } -#endif - - return scene::INodePtr(); - -#if 0 - if (patch1.getWidth() == patch2.getHeight()) - { - row1 = 0; - col2 = 0; - - while (1) - { - match = false; - - col1 = 0; - adj1 = 1; - - row2 = 0; - adj2 = 1; - - if (getControl(patch1, row1, 0).vertex.isEqual(getControl(patch2, 0, col2).vertex, WELD_EPSILON)) - {} - else if (getControl(patch1, row1, 0).vertex.isEqual(getControl(patch2, patch2.getHeight() - 1, col2).vertex, WELD_EPSILON)) - { - row2 = patch2.getHeight() - 1; - adj2 = -1; - } - else if (getControl(patch1, row1, patch1.getWidth() - 1).vertex.isEqual(getControl(patch2, patch2.getHeight() - 1, col2).vertex, WELD_EPSILON)) - { - row2 = patch2.getHeight() - 1; - adj2 = -1; - - col1 = patch1.getWidth() - 1; - adj1 = -1; - } - else if (getControl(patch1, row1, patch1.getWidth() - 1).vertex.isEqual(getControl(patch2, 0, col2).vertex, WELD_EPSILON)) - { - col1 = patch1.getWidth() - 1; - adj1 = -1; - } - else - { - adj1 = 0; - } - - if (adj1) - { - match = true; - - for (col = 0; col < patch1.getWidth(); col++, col1 += adj1, row2 += adj2) - { - if (!getControl(patch1, row1, col1).vertex.isEqual(getControl(patch2, row2, col2).vertex, WELD_EPSILON)) - { - match = false; - break; - } - } - } - - if (match) - { - rMessage() << "Welding row " << row1 << " with column " << col2 << std::endl; - - row1 = (row1 == 0) ? patch1.getHeight() - 1 : 0; - - return createdMergedPatch(patchNode1, patchNode2, -1, col2, row1, -1, (adj1 == -1), (adj2 == -1)); - } - - if (col2 == 0) - { - col2 = patch2.getWidth() - 1; - } - else if (row1 == 0) - { - row1 = patch1.getHeight() - 1; - col2 = 0; - } - else - { - break; - } - } - } - - if (patch1.getHeight() == patch2.getWidth()) - { - col1 = 0; - row2 = 0; - - while (1) - { - match = false; - - row1 = 0; - adj1 = 1; - - col2 = 0; - adj2 = 1; - - if (getControl(patch1, 0, col1).vertex.isEqual(getControl(patch2, row2, 0).vertex, WELD_EPSILON)) - {} - else if (getControl(patch1, 0, col1).vertex.isEqual(getControl(patch2, patch2.getWidth() - 1, row2).vertex, WELD_EPSILON)) - { - col2 = patch2.getWidth() - 1; - adj2 = -1; - } - else if (getControl(patch1, patch1.getHeight() - 1, col1).vertex.isEqual(getControl(patch2, patch2.getWidth() - 1, row2).vertex, WELD_EPSILON)) - { - col2 = patch2.getWidth() - 1; - adj2 = -1; - - row1 = patch2.getHeight() - 1; - adj1 = -1; - } - else if (getControl(patch1, patch1.getHeight() - 1, col1).vertex.isEqual(getControl(patch2, row2, 0).vertex, WELD_EPSILON)) - { - row1 = patch2.getHeight() - 1; - adj2 = -1; - } - else - { - adj1 = 0; - } - - if (adj1) - { - match = true; - - for (row = 0; row < patch1.getHeight(); row++, row1 += adj1, col2 += adj2) - { - if (!getControl(patch1, row1, col1).vertex.isEqual(getControl(patch2, row2, col2).vertex, WELD_EPSILON)) - { - match = false; - break; - } - } - } - - if (match) - { - rMessage() << "Welding column " << col1 << " with row " << row2 << std::endl; - - col1 = (col1 == 0) ? patch1.getWidth() - 1 : 0; - - return createdMergedPatch(patchNode1, patchNode2, col1, -1, -1, row2, (adj1 == -1), (adj2 == -1)); - } - - if (row2 == 0) - { - row2 = patch2.getHeight() - 1; - } - else if (col1 == 0) - { - col1 = patch1.getWidth() - 1; - row2 = 0; - } - else - { - break; - } - } - } - - if (patch1.getHeight() == patch2.getHeight()) - { - col1 = 0; - col2 = 0; - - while (1) - { - match = false; - - row1 = 0; - adj1 = 1; - - row2 = 0; - adj2 = 1; - - if (getControl(patch1, 0, col1).vertex.isEqual(getControl(patch2, 0, col2).vertex, WELD_EPSILON)) - {} - else if (getControl(patch1, 0, col1).vertex.isEqual(getControl(patch2, patch2.getHeight() - 1, col2).vertex, WELD_EPSILON)) - { - row2 = patch2.getHeight() - 1; - adj2 = -1; - } - else if (getControl(patch1, patch1.getHeight() - 1, col1).vertex.isEqual(getControl(patch2, patch2.getHeight() - 1, col2).vertex, WELD_EPSILON)) - { - row2 = patch2.getHeight() - 1; - adj2 = -1; - - row1 = patch1.getHeight() - 1; - adj1 = -1; - } - else if (getControl(patch1, patch1.getHeight() - 1, col1).vertex.isEqual(getControl(patch2, 0, col2).vertex, WELD_EPSILON)) - { - row1 = patch1.getHeight() - 1; - adj1 = -1; - } - else - { - adj1 = 0; - } - - if (adj1) - { - match = true; - - for (row = 0; row < patch1.getHeight(); row++, row1 += adj1, row2 += adj2) - { - if (!getControl(patch1, row1, col1).vertex.isEqual(getControl(patch2, row2, col2).vertex, WELD_EPSILON)) - { - match = false; - break; - } - } - } - - if (match) - { - rMessage() << "Welding column " << col1 << " with column " << col2 << std::endl; - - col1 = (col1 == 0) ? patch1.getWidth() - 1 : 0; - - return createdMergedPatch(patchNode1, patchNode2, col1, col2, -1, -1, (adj1 == -1), (adj2 == -1)); - } - - if (col2 == 0) - { - col2 = patch2.getWidth() - 1; - } - else if (col1 == 0) - { - col1 = patch1.getWidth() - 1; - col2 = 0; - } - else - { - break; - } - } - } -#endif throw cmd::ExecutionFailure(_("Unable to weld patches, no suitable edges of same length found")); } @@ -978,11 +313,6 @@ void weldPatches(const PatchNodePtr& patchNode1, const PatchNodePtr& patchNode2) { auto mergedPatch = createdMergedPatch(patchNode1, patchNode2); - if (!mergedPatch) - { - throw cmd::ExecutionFailure(_("Failed to weld patches.")); - } - patchNode1->getParent()->addChildNode(mergedPatch); mergedPatch->assignToLayers(patchNode1->getLayers());