diff --git a/.clang-format b/.clang-format
new file mode 100644
index 00000000..a2d84ede
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,216 @@
+---
+Language: Cpp
+# BasedOnStyle: LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignArrayOfStructures: None
+AlignConsecutiveAssignments:
+ Enabled: false
+ AcrossEmptyLines: false
+ AcrossComments: false
+ AlignCompound: false
+ PadOperators: true
+AlignConsecutiveBitFields:
+ Enabled: false
+ AcrossEmptyLines: false
+ AcrossComments: false
+ AlignCompound: false
+ PadOperators: false
+AlignConsecutiveDeclarations:
+ Enabled: false
+ AcrossEmptyLines: false
+ AcrossComments: false
+ AlignCompound: false
+ PadOperators: false
+AlignConsecutiveMacros:
+ Enabled: false
+ AcrossEmptyLines: false
+ AcrossComments: false
+ AlignCompound: false
+ PadOperators: false
+AlignEscapedNewlines: Right
+AlignOperands: Align
+AlignTrailingComments: true
+AllowAllArgumentsOnNextLine: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortEnumsOnASingleLine: true
+AllowShortBlocksOnASingleLine: Never
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: All
+AllowShortLambdasOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: Never
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: MultiLine
+AttributeMacros:
+ - __capability
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterCaseLabel: false
+ AfterClass: false
+ AfterControlStatement: Never
+ AfterEnum: false
+ AfterFunction: false
+ AfterNamespace: true
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ BeforeLambdaBody: false
+ BeforeWhile: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeConceptDeclarations: Always
+BreakBeforeBraces: Attach
+BreakBeforeInheritanceComma: false
+BreakInheritanceList: BeforeColon
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeColon
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit: 120
+CommentPragmas: '^ IWYU pragma:'
+QualifierAlignment: Leave
+CompactNamespaces: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DeriveLineEnding: true
+DerivePointerAlignment: false
+DisableFormat: false
+EmptyLineAfterAccessModifier: Never
+EmptyLineBeforeAccessModifier: LogicalBlock
+ExperimentalAutoDetectBinPacking: false
+PackConstructorInitializers: BinPack
+BasedOnStyle: ''
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+AllowAllConstructorInitializersOnNextLine: true
+FixNamespaceComments: true
+ForEachMacros:
+ - foreach
+ - Q_FOREACH
+ - BOOST_FOREACH
+IfMacros:
+ - KJ_IF_MAYBE
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
+ Priority: 2
+ SortPriority: 0
+ CaseSensitive: false
+ - Regex: '^(<|"(gtest|gmock|isl|json)/)'
+ Priority: 3
+ SortPriority: 0
+ CaseSensitive: false
+ - Regex: '.*'
+ Priority: 1
+ SortPriority: 0
+ CaseSensitive: false
+IncludeIsMainRegex: '(Test)?$'
+IncludeIsMainSourceRegex: ''
+IndentAccessModifiers: false
+IndentCaseLabels: false
+IndentCaseBlocks: false
+IndentGotoLabels: true
+IndentPPDirectives: None
+IndentExternBlock: AfterExternBlock
+IndentRequiresClause: true
+IndentWidth: 4
+IndentWrappedFunctionNames: false
+InsertBraces: false
+InsertTrailingCommas: None
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+LambdaBodyIndentation: Signature
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 2
+ObjCBreakBeforeNestedBlockParam: true
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakOpenParenthesis: 0
+PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PenaltyIndentedWhitespace: 0
+PointerAlignment: Right
+PPIndentWidth: -1
+ReferenceAlignment: Pointer
+ReflowComments: true
+RemoveBracesLLVM: false
+RequiresClausePosition: OwnLine
+SeparateDefinitionBlocks: Leave
+ShortNamespaceLines: 1
+SortIncludes: CaseSensitive
+SortJavaStaticImport: Before
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCaseColon: false
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatements
+SpaceBeforeParensOptions:
+ AfterControlStatements: true
+ AfterForeachMacros: true
+ AfterFunctionDefinitionName: false
+ AfterFunctionDeclarationName: false
+ AfterIfMacros: true
+ AfterOverloadedOperator: false
+ AfterRequiresInClause: false
+ AfterRequiresInExpression: false
+ BeforeNonEmptyParentheses: false
+SpaceAroundPointerQualifiers: Default
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyBlock: false
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: Never
+SpacesInConditionalStatement: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInLineCommentPrefix:
+ Minimum: 1
+ Maximum: -1
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+SpaceBeforeSquareBrackets: false
+BitFieldColonSpacing: Both
+Standard: Latest
+StatementAttributeLikeMacros:
+ - Q_EMIT
+StatementMacros:
+ - Q_UNUSED
+ - QT_REQUIRE_VERSION
+TabWidth: 4
+UseCRLF: false
+UseTab: Never
+WhitespaceSensitiveMacros:
+ - STRINGIZE
+ - PP_STRINGIZE
+ - BOOST_PP_STRINGIZE
+ - NS_SWIFT_NAME
+ - CF_SWIFT_NAME
+...
+
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 00000000..8ca73a92
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,12 @@
+# top-most EditorConfig file
+root = true
+
+[*]
+trim_trailing_whitespace = true
+insert_final_newline = true
+end_of_line = lf
+charset = utf-8
+
+[*.{c,h,cpp,hpp}]
+indent_style = space
+indent_size = 4
diff --git a/src/algo/adaptivewaterline.cpp b/src/algo/adaptivewaterline.cpp
index 40767c97..42e37fa7 100644
--- a/src/algo/adaptivewaterline.cpp
+++ b/src/algo/adaptivewaterline.cpp
@@ -1,59 +1,56 @@
/* $Id$
- *
+ *
* Copyright (c) 2010-2011 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#include
#include
-
-#include
+#include
#ifdef _OPENMP
- #include
+#include
#endif
+#include "line.hpp"
#include "millingcutter.hpp"
+#include "path.hpp"
#include "point.hpp"
#include "triangle.hpp"
-#include "line.hpp"
-#include "path.hpp"
#include "adaptivewaterline.hpp"
-#include "weave.hpp"
#include "fiberpushcutter.hpp"
+#include "weave.hpp"
-
-namespace ocl
-{
+namespace ocl {
//******** ********************** */
AdaptiveWaterline::AdaptiveWaterline() {
subOp.clear();
- subOp.push_back( new FiberPushCutter() );
- subOp.push_back( new FiberPushCutter() );
+ subOp.push_back(new FiberPushCutter());
+ subOp.push_back(new FiberPushCutter());
subOp[0]->setXDirection();
subOp[1]->setYDirection();
- nthreads=1;
+ nthreads = 1;
#ifdef _OPENMP
- nthreads = omp_get_num_procs();
+ nthreads = omp_get_num_procs();
// omp_set_dynamic(0);
// omp_set_nested(1);
#endif
@@ -80,151 +77,153 @@ void AdaptiveWaterline::run2() {
}
void AdaptiveWaterline::adaptive_sampling_run() {
- minx = surf->bb.minpt.x - 2*cutter->getRadius();
- maxx = surf->bb.maxpt.x + 2*cutter->getRadius();
- miny = surf->bb.minpt.y - 2*cutter->getRadius();
- maxy = surf->bb.maxpt.y + 2*cutter->getRadius();
- Line* line = new Line( Point(minx,miny,zh) , Point(maxx,maxy,zh) );
- Span* linespan = new LineSpan(*line);
-
+ minx = surf->bb.minpt.x - 2 * cutter->getRadius();
+ maxx = surf->bb.maxpt.x + 2 * cutter->getRadius();
+ miny = surf->bb.minpt.y - 2 * cutter->getRadius();
+ maxy = surf->bb.maxpt.y + 2 * cutter->getRadius();
+ Line *line = new Line(Point(minx, miny, zh), Point(maxx, maxy, zh));
+ Span *linespan = new LineSpan(*line);
+
#ifdef _WIN32 // OpenMP task not supported with the version 2 of VS2013 OpenMP
- #pragma omp parallel sections
- {
- #pragma omp section // Replace OMP Task by Parallel sections
- { // first child
+#pragma omp parallel sections
+ {
+#pragma omp section // Replace OMP Task by Parallel sections
+ { // first child
#else
#pragma omp parallel
- {
+ {
#pragma omp single nowait
- { // initial root task
+ { // initial root task
#pragma omp task
- { // first child task
+ { // first child task
#endif // _WIN32
- xfibers.clear();
- Point xstart_p1 = Point(minx, linespan->getPoint(0.0).y, zh);
- Point xstart_p2 = Point(maxx, linespan->getPoint(0.0).y, zh);
- Point xstop_p1 = Point(minx, linespan->getPoint(1.0).y, zh);
- Point xstop_p2 = Point(maxx, linespan->getPoint(1.0).y, zh);
- Fiber xstart_f = Fiber(xstart_p1, xstart_p2);
- Fiber xstop_f = Fiber(xstop_p1, xstop_p2);
- subOp[0]->run(xstart_f);
- subOp[0]->run(xstop_f);
- xfibers.push_back(xstart_f);
- // std::cout << " XFiber adaptive sample \n";
- xfiber_adaptive_sample(linespan, 0.0, 1.0, xstart_f, xstop_f);
+ xfibers.clear();
+ Point xstart_p1 = Point(minx, linespan->getPoint(0.0).y, zh);
+ Point xstart_p2 = Point(maxx, linespan->getPoint(0.0).y, zh);
+ Point xstop_p1 = Point(minx, linespan->getPoint(1.0).y, zh);
+ Point xstop_p2 = Point(maxx, linespan->getPoint(1.0).y, zh);
+ Fiber xstart_f = Fiber(xstart_p1, xstart_p2);
+ Fiber xstop_f = Fiber(xstop_p1, xstop_p2);
+ subOp[0]->run(xstart_f);
+ subOp[0]->run(xstop_f);
+ xfibers.push_back(xstart_f);
+ // std::cout << " XFiber adaptive sample \n";
+ xfiber_adaptive_sample(linespan, 0.0, 1.0, xstart_f, xstop_f);
#ifdef _WIN32 // OpenMP task not supported with the version 2 of VS2013 OpenMP
- }
- #pragma omp section
- { // second child
+ }
+#pragma omp section
+ {// second child
#else
- }
-# pragma omp task
- { // second child task
+ }
+#pragma omp task
+ { // second child task
#endif // _WIN32
- yfibers.clear();
- Point ystart_p1 = Point(linespan->getPoint(0.0).x, miny, zh);
- Point ystart_p2 = Point(linespan->getPoint(0.0).x, maxy, zh);
- Point ystop_p1 = Point(linespan->getPoint(1.0).x, miny, zh);
- Point ystop_p2 = Point(linespan->getPoint(1.0).x, maxy, zh);
- Fiber ystart_f = Fiber(ystart_p1, ystart_p2);
- Fiber ystop_f = Fiber(ystop_p1, ystop_p2);
- subOp[1]->run(ystart_f);
- subOp[1]->run(ystop_f);
- yfibers.push_back(ystart_f);
- // std::cout << " YFiber adaptive sample \n";
- yfiber_adaptive_sample(linespan, 0.0, 1.0, ystart_f, ystop_f);
+ yfibers.clear();
+ Point ystart_p1 = Point(linespan->getPoint(0.0).x, miny, zh);
+ Point ystart_p2 = Point(linespan->getPoint(0.0).x, maxy, zh);
+ Point ystop_p1 = Point(linespan->getPoint(1.0).x, miny, zh);
+ Point ystop_p2 = Point(linespan->getPoint(1.0).x, maxy, zh);
+ Fiber ystart_f = Fiber(ystart_p1, ystart_p2);
+ Fiber ystop_f = Fiber(ystop_p1, ystop_p2);
+ subOp[1]->run(ystart_f);
+ subOp[1]->run(ystop_f);
+ yfibers.push_back(ystart_f);
+ // std::cout << " YFiber adaptive sample \n";
+ yfiber_adaptive_sample(linespan, 0.0, 1.0, ystart_f, ystop_f);
#ifdef _WIN32 // OpenMP task not supported with the version 2 of VS2013 OpenMP
- }
- } // end omp parallel
+ }
+} // end omp parallel
#else
}
}
} // end omp parallel
#endif // _WIN32
- delete line;
- delete linespan;
-
-}
-
-
-void AdaptiveWaterline::xfiber_adaptive_sample(const Span* span, double start_t, double stop_t, Fiber start_f, Fiber stop_f) {
- const double mid_t = start_t + (stop_t-start_t)/2.0; // mid point sample
- assert( mid_t > start_t ); assert( mid_t < stop_t );
- //std::cout << "xfiber sample= ( " << start_t << " , " << stop_t << " ) \n";
- Point mid_p1 = Point( minx, span->getPoint( mid_t ).y, zh );
- Point mid_p2 = Point( maxx, span->getPoint( mid_t ).y, zh );
- Fiber mid_f = Fiber( mid_p1, mid_p2 );
- subOp[0]->run( mid_f );
- double fw_step = fabs( start_f.p1.y - stop_f.p1.y ) ;
- if ( fw_step > sampling ) { // above minimum step-forward, need to sample more
- xfiber_adaptive_sample( span, start_t, mid_t , start_f, mid_f );
- xfiber_adaptive_sample( span, mid_t , stop_t, mid_f , stop_f );
- } else if ( !flat(start_f,mid_f,stop_f) ) {
+delete line;
+delete linespan;
+
+} // namespace ocl
+
+void AdaptiveWaterline::xfiber_adaptive_sample(const Span *span, double start_t, double stop_t, Fiber start_f,
+ Fiber stop_f) {
+ const double mid_t = start_t + (stop_t - start_t) / 2.0; // mid point sample
+ assert(mid_t > start_t);
+ assert(mid_t < stop_t);
+ // std::cout << "xfiber sample= ( " << start_t << " , " << stop_t << " ) \n";
+ Point mid_p1 = Point(minx, span->getPoint(mid_t).y, zh);
+ Point mid_p2 = Point(maxx, span->getPoint(mid_t).y, zh);
+ Fiber mid_f = Fiber(mid_p1, mid_p2);
+ subOp[0]->run(mid_f);
+ double fw_step = fabs(start_f.p1.y - stop_f.p1.y);
+ if (fw_step > sampling) { // above minimum step-forward, need to sample more
+ xfiber_adaptive_sample(span, start_t, mid_t, start_f, mid_f);
+ xfiber_adaptive_sample(span, mid_t, stop_t, mid_f, stop_f);
+ } else if (!flat(start_f, mid_f, stop_f)) {
if (fw_step > min_sampling) { // not a flat segment, and we have not reached maximum sampling
- xfiber_adaptive_sample( span, start_t, mid_t , start_f, mid_f );
- xfiber_adaptive_sample( span, mid_t , stop_t, mid_f , stop_f );
+ xfiber_adaptive_sample(span, start_t, mid_t, start_f, mid_f);
+ xfiber_adaptive_sample(span, mid_t, stop_t, mid_f, stop_f);
}
} else {
xfibers.push_back(stop_f);
- }
+ }
}
-void AdaptiveWaterline::yfiber_adaptive_sample(const Span* span, double start_t, double stop_t, Fiber start_f, Fiber stop_f) {
- const double mid_t = start_t + (stop_t-start_t)/2.0; // mid point sample
- assert( mid_t > start_t ); assert( mid_t < stop_t );
- //std::cout << "yfiber sample= ( " << start_t << " , " << stop_t << " ) \n";
- Point mid_p1 = Point( span->getPoint( mid_t ).x, miny, zh );
- Point mid_p2 = Point( span->getPoint( mid_t ).x, maxy, zh );
- Fiber mid_f = Fiber( mid_p1, mid_p2 );
- subOp[1]->run( mid_f );
- double fw_step = fabs( start_f.p1.x - stop_f.p1.x ) ;
- if ( fw_step > sampling ) { // above minimum step-forward, need to sample more
- yfiber_adaptive_sample( span, start_t, mid_t , start_f, mid_f );
- yfiber_adaptive_sample( span, mid_t , stop_t, mid_f , stop_f );
- } else if ( !flat(start_f,mid_f,stop_f) ) {
+void AdaptiveWaterline::yfiber_adaptive_sample(const Span *span, double start_t, double stop_t, Fiber start_f,
+ Fiber stop_f) {
+ const double mid_t = start_t + (stop_t - start_t) / 2.0; // mid point sample
+ assert(mid_t > start_t);
+ assert(mid_t < stop_t);
+ // std::cout << "yfiber sample= ( " << start_t << " , " << stop_t << " ) \n";
+ Point mid_p1 = Point(span->getPoint(mid_t).x, miny, zh);
+ Point mid_p2 = Point(span->getPoint(mid_t).x, maxy, zh);
+ Fiber mid_f = Fiber(mid_p1, mid_p2);
+ subOp[1]->run(mid_f);
+ double fw_step = fabs(start_f.p1.x - stop_f.p1.x);
+ if (fw_step > sampling) { // above minimum step-forward, need to sample more
+ yfiber_adaptive_sample(span, start_t, mid_t, start_f, mid_f);
+ yfiber_adaptive_sample(span, mid_t, stop_t, mid_f, stop_f);
+ } else if (!flat(start_f, mid_f, stop_f)) {
if (fw_step > min_sampling) { // not a flat segment, and we have not reached maximum sampling
- yfiber_adaptive_sample( span, start_t, mid_t , start_f, mid_f );
- yfiber_adaptive_sample( span, mid_t , stop_t, mid_f , stop_f );
+ yfiber_adaptive_sample(span, start_t, mid_t, start_f, mid_f);
+ yfiber_adaptive_sample(span, mid_t, stop_t, mid_f, stop_f);
}
} else {
- yfibers.push_back(stop_f);
+ yfibers.push_back(stop_f);
}
}
// flat predicate to determine when we subdivide
-bool AdaptiveWaterline::flat( Fiber& start, Fiber& mid, Fiber& stop ) const {
- if ( start.size() != stop.size() ) // start, mid, and stop need to have same size()
+bool AdaptiveWaterline::flat(Fiber &start, Fiber &mid, Fiber &stop) const {
+ if (start.size() != stop.size()) // start, mid, and stop need to have same size()
return false;
- else if ( start.size() != mid.size() )
+ else if (start.size() != mid.size())
return false;
- else if ( mid.size() != stop.size() )
+ else if (mid.size() != stop.size())
return false;
else {
- if (!start.empty() ) { // all now have same size
- assert( start.size() == stop.size() && start.size() == mid.size() );
- for (unsigned int n=0;ncosLimit);
+ double dotprod = v1.dot(v2);
+ return (dotprod > cosLimit);
}
-}// end namespace
+} // namespace ocl
// end file adaptivewaterline.cpp
diff --git a/src/algo/adaptivewaterline.hpp b/src/algo/adaptivewaterline.hpp
index e00042c0..8468350b 100644
--- a/src/algo/adaptivewaterline.hpp
+++ b/src/algo/adaptivewaterline.hpp
@@ -1,23 +1,23 @@
/* $Id$
- *
+ *
* Copyright (c) 2010 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#ifndef ADAPTIVEWATERLINE_HPP
#define ADAPTIVEWATERLINE_HPP
@@ -28,65 +28,63 @@
#include
-#include "waterline.hpp"
#include "fiber.hpp"
+#include "waterline.hpp"
-namespace ocl
-{
+namespace ocl {
class Span;
/// \brief a Waterline toolpath follows the shape of the model at a constant z-height in the xy-plane
class AdaptiveWaterline : public Waterline {
- public:
- /// create an empty Waterline object
- AdaptiveWaterline();
- virtual ~AdaptiveWaterline();
- /// set the minimum sampling interval
- void setMinSampling(double s) {min_sampling=s;}
- /// set the cosine limit for the flat() predicate
- void setCosLimit(double lim) {cosLimit=lim;}
-
- /// run the Waterline algorithm. setSTL, setCutter, setSampling, and setZ must
- /// be called before a call to run()
- void run();
- void run2();
-
- virtual void setSampling(double s) {
- sampling=s;
- min_sampling = sampling/10.0; // default to this when setMinSampling is not called
- }
-
-
- protected:
- /// adaptive waterline algorithm
- void adaptive_sampling_run();
- /// x-direction adaptive sampling
- void xfiber_adaptive_sample(const Span* span, double start_t, double stop_t, Fiber start_f, Fiber stop_f);
- /// y-direction adaptive sampling
- void yfiber_adaptive_sample(const Span* span, double start_t, double stop_t, Fiber start_f, Fiber stop_f);
- /// flatness predicate for fibers. Checks Fiber.size() and then calls flat() on cl-points
- bool flat( Fiber& start, Fiber& mid, Fiber& stop ) const;
- /// flatness predicate for cl-points. checks for angle metween start-mid-stop
- bool flat(Point start_cl, Point mid_cl, Point stop_cl) const;
+ public:
+ /// create an empty Waterline object
+ AdaptiveWaterline();
+ virtual ~AdaptiveWaterline();
+ /// set the minimum sampling interval
+ void setMinSampling(double s) { min_sampling = s; }
+ /// set the cosine limit for the flat() predicate
+ void setCosLimit(double lim) { cosLimit = lim; }
+
+ /// run the Waterline algorithm. setSTL, setCutter, setSampling, and setZ must
+ /// be called before a call to run()
+ void run();
+ void run2();
+
+ virtual void setSampling(double s) {
+ sampling = s;
+ min_sampling = sampling / 10.0; // default to this when setMinSampling is not called
+ }
+
+ protected:
+ /// adaptive waterline algorithm
+ void adaptive_sampling_run();
+ /// x-direction adaptive sampling
+ void xfiber_adaptive_sample(const Span *span, double start_t, double stop_t, Fiber start_f, Fiber stop_f);
+ /// y-direction adaptive sampling
+ void yfiber_adaptive_sample(const Span *span, double start_t, double stop_t, Fiber start_f, Fiber stop_f);
+ /// flatness predicate for fibers. Checks Fiber.size() and then calls flat() on cl-points
+ bool flat(Fiber &start, Fiber &mid, Fiber &stop) const;
+ /// flatness predicate for cl-points. checks for angle metween start-mid-stop
+ bool flat(Point start_cl, Point mid_cl, Point stop_cl) const;
// DATA
- /// minimum x-coordinate
- double minx;
- /// maximum x-coordinate
- double maxx;
- /// minimum y-coordinate
- double miny;
- /// maximum y-coordinate
- double maxy;
- /// the minimum sampling interval when subdividing
- double min_sampling;
- /// the cosine limit value for cl-point flat(). In the constructor, cosLimit = 0.999 by default.
- double cosLimit;
+ /// minimum x-coordinate
+ double minx;
+ /// maximum x-coordinate
+ double maxx;
+ /// minimum y-coordinate
+ double miny;
+ /// maximum y-coordinate
+ double maxy;
+ /// the minimum sampling interval when subdividing
+ double min_sampling;
+ /// the cosine limit value for cl-point flat(). In the constructor, cosLimit = 0.999 by default.
+ double cosLimit;
};
-} // end namespace
+} // namespace ocl
#endif
diff --git a/src/algo/batchpushcutter.cpp b/src/algo/batchpushcutter.cpp
index e6b17026..f15c87ea 100644
--- a/src/algo/batchpushcutter.cpp
+++ b/src/algo/batchpushcutter.cpp
@@ -1,37 +1,36 @@
/* $Id$
- *
+ *
* Copyright (c) 2010-2011 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#include
-#ifdef _OPENMP
- #include
+#ifdef _OPENMP
+#include
#endif
+#include "batchpushcutter.hpp"
#include "millingcutter.hpp"
#include "point.hpp"
#include "triangle.hpp"
-#include "batchpushcutter.hpp"
-namespace ocl
-{
+namespace ocl {
//******** ********************** */
@@ -55,7 +54,7 @@ BatchPushCutter::~BatchPushCutter() {
void BatchPushCutter::setSTL(const STLSurf &s) {
surf = &s;
// std::cout << "BPC::setSTL() Building kd-tree... bucketSize=" << bucketSize << "..";
- root->setBucketSize( bucketSize );
+ root->setBucketSize(bucketSize);
if (x_direction)
root->setYZDimensions(); // we search for triangles in the XY plane, don't care about Z-coordinate
else if (y_direction)
@@ -69,24 +68,20 @@ void BatchPushCutter::setSTL(const STLSurf &s) {
// std::cout << "done.\n";
}
-void BatchPushCutter::appendFiber(Fiber& f) {
- fibers->push_back(f);
-}
+void BatchPushCutter::appendFiber(Fiber &f) { fibers->push_back(f); }
-void BatchPushCutter::reset() {
- fibers->clear();
-}
+void BatchPushCutter::reset() { fibers->clear(); }
/// very simple batch push-cutter
/// each fiber is tested against all triangles of surface
void BatchPushCutter::pushCutter1() {
- // std::cout << "BatchPushCutter1 with " << fibers->size() <<
+ // std::cout << "BatchPushCutter1 with " << fibers->size() <<
// " fibers and " << surf->tris.size() << " triangles..." << std::endl;
nCalls = 0;
- BOOST_FOREACH(Fiber& f, *fibers) {
- BOOST_FOREACH( const Triangle& t, surf->tris) {// test against all triangles in s
+ BOOST_FOREACH (Fiber &f, *fibers) {
+ BOOST_FOREACH (const Triangle &t, surf->tris) { // test against all triangles in s
Interval i;
- cutter->pushCutter(f,i,t);
+ cutter->pushCutter(f, i, t);
f.addInterval(i);
++nCalls;
}
@@ -95,14 +90,14 @@ void BatchPushCutter::pushCutter1() {
return;
}
-/// push-cutter which uses KDNode2 kd-tree search to find triangles
+/// push-cutter which uses KDNode2 kd-tree search to find triangles
/// overlapping with the cutter.
void BatchPushCutter::pushCutter2() {
- // std::cout << "BatchPushCutter2 with " << fibers->size() <<
+ // std::cout << "BatchPushCutter2 with " << fibers->size() <<
// " fibers and " << surf->tris.size() << " triangles..." << std::endl;
nCalls = 0;
- std::list* overlap_triangles;
- BOOST_FOREACH(Fiber& f, *fibers) {
+ std::list *overlap_triangles;
+ BOOST_FOREACH (Fiber &f, *fibers) {
CLPoint cl;
if (x_direction) {
cl.x = 0;
@@ -116,16 +111,16 @@ void BatchPushCutter::pushCutter2() {
assert(0);
}
overlap_triangles = root->search_cutter_overlap(cutter, &cl);
- assert( overlap_triangles->size() <= surf->size() ); // can't possibly find more triangles than in the STLSurf
- BOOST_FOREACH( const Triangle& t, *overlap_triangles) {
- //if ( bb->overlaps( t.bb ) ) {
- Interval i;
- cutter->pushCutter(f,i,t);
- f.addInterval(i);
- ++nCalls;
+ assert(overlap_triangles->size() <= surf->size()); // can't possibly find more triangles than in the STLSurf
+ BOOST_FOREACH (const Triangle &t, *overlap_triangles) {
+ // if ( bb->overlaps( t.bb ) ) {
+ Interval i;
+ cutter->pushCutter(f, i, t);
+ f.addInterval(i);
+ ++nCalls;
//}
}
- delete( overlap_triangles );
+ delete (overlap_triangles);
}
// std::cout << "BatchPushCutter2 done." << std::endl;
return;
@@ -134,58 +129,58 @@ void BatchPushCutter::pushCutter2() {
/// use kd-tree search to find overlapping triangles
/// use OpenMP for multi-threading
void BatchPushCutter::pushCutter3() {
- // std::cout << "BatchPushCutter3 with " << fibers->size() <<
+ // std::cout << "BatchPushCutter3 with " << fibers->size() <<
// " fibers and " << surf->tris.size() << " triangles." << std::endl;
// std::cout << " cutter = " << cutter->str() << "\n";
nCalls = 0;
#ifdef _OPENMP
omp_set_num_threads(nthreads);
#endif
- std::list::iterator it,it_end; // for looping over found triabgles
- Interval* i;
- std::list* tris;
- std::vector& fiberr = *fibers;
-#ifdef _WIN32 // OpenMP version 2 of VS2013 OpenMP need signed loop variable
- int n; // loop variable
- int Nmax = static_cast(fibers->size()); // the number of fibers to process
+ std::list::iterator it, it_end; // for looping over found triabgles
+ Interval *i;
+ std::list *tris;
+ std::vector &fiberr = *fibers;
+#ifdef _WIN32 // OpenMP version 2 of VS2013 OpenMP need signed loop variable
+ int n; // loop variable
+ int Nmax = static_cast(fibers->size()); // the number of fibers to process
#else
- unsigned int n; // loop variable
- unsigned int Nmax = fibers->size(); // the number of fibers to process
+ unsigned int n; // loop variable
+ unsigned int Nmax = fibers->size(); // the number of fibers to process
#endif
- unsigned int calls=0;
-
- #pragma omp parallel for schedule(dynamic) shared(calls, fiberr) private(n,i,tris,it,it_end)
- //#pragma omp parallel for shared( calls, fiberr) private(n,i,tris,it,it_end)
- for (n=0; nsearch_cutter_overlap(cutter, &cl);
it_end = tris->end();
- for ( it=tris->begin() ; it!=it_end ; ++it) { // loop through the found overlapping triangles
- //if ( bb->overlaps( it->bb ) ) {
- // todo: optimization where method-calls are skipped if triangle bbox already in the fiber
- i = new Interval();
- cutter->pushCutter(fiberr[n],*i,*it);
- fiberr[n].addInterval(*i);
- ++calls;
- delete i;
+ for (it = tris->begin(); it != it_end; ++it) { // loop through the found overlapping triangles
+ // if ( bb->overlaps( it->bb ) ) {
+ // todo: optimization where method-calls are skipped if triangle bbox already in the fiber
+ i = new Interval();
+ cutter->pushCutter(fiberr[n], *i, *it);
+ fiberr[n].addInterval(*i);
+ ++calls;
+ delete i;
//}
}
- delete( tris );
+ delete (tris);
} // OpenMP parallel region ends here
-
+
this->nCalls = calls;
// std::cout << "\nBatchPushCutter3 done." << std::endl;
return;
}
-}// end namespace
+} // namespace ocl
// end file batchpushcutter.cpp
diff --git a/src/algo/batchpushcutter.hpp b/src/algo/batchpushcutter.hpp
index 943bb0d7..554ad8bd 100644
--- a/src/algo/batchpushcutter.hpp
+++ b/src/algo/batchpushcutter.hpp
@@ -1,23 +1,23 @@
/* $Id$
- *
+ *
* Copyright (c) 2010 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#ifndef BPC_H
#define BPC_H
@@ -26,13 +26,12 @@
#include
#include
-#include "point.hpp"
#include "fiber.hpp"
#include "kdtree.hpp"
#include "operation.hpp"
+#include "point.hpp"
-namespace ocl
-{
+namespace ocl {
class STLSurf;
class Triangle;
@@ -44,45 +43,51 @@ class MillingCutter;
/// When this runs the Fibers will be updated with the correct interval data.
/// This is then used to build a weave and extract a waterline.
class BatchPushCutter : public Operation {
- public:
- BatchPushCutter();
- virtual ~BatchPushCutter();
-
- /// set the STL-surface and build kd-tree
- void setSTL(const STLSurf& s);
+ public:
+ BatchPushCutter();
+ virtual ~BatchPushCutter();
+
+ /// set the STL-surface and build kd-tree
+ void setSTL(const STLSurf &s);
+
+ /// set this bpc to be x-direction
+ void setXDirection() {
+ x_direction = true;
+ y_direction = false;
+ }
+ /// set this bpc to be Y-direction
+ void setYDirection() {
+ x_direction = false;
+ y_direction = true;
+ }
+ /// append to list of Fibers to evaluate
+ void appendFiber(Fiber &f);
+
+ /// run push-cutter
+ void run() { this->pushCutter3(); }
+ // void run() {this->pushCutter1();}
+
+ std::vector *getFibers() const { return fibers; }
+ void reset();
+
+ protected:
+ /// 1st version of algorithm
+ void pushCutter1();
+ /// 2nd version of algorithm
+ void pushCutter2();
+ /// 3rd version of algorithm
+ void pushCutter3();
- /// set this bpc to be x-direction
- void setXDirection() {x_direction=true;y_direction=false;}
- /// set this bpc to be Y-direction
- void setYDirection() {x_direction=false;y_direction=true;}
- /// append to list of Fibers to evaluate
- void appendFiber(Fiber& f);
+ /// pointer to list of Fibers
+ std::vector *fibers;
-
- /// run push-cutter
- void run() {this->pushCutter3();}
- //void run() {this->pushCutter1();}
-
- std::vector* getFibers() const {return fibers;}
- void reset();
- protected:
- /// 1st version of algorithm
- void pushCutter1();
- /// 2nd version of algorithm
- void pushCutter2();
- /// 3rd version of algorithm
- void pushCutter3();
-
- /// pointer to list of Fibers
- std::vector* fibers;
-
// DATA
- /// true if this we have only x-direction fibers
- bool x_direction;
- /// true if we have y-direction fibers
- bool y_direction;
+ /// true if this we have only x-direction fibers
+ bool x_direction;
+ /// true if we have y-direction fibers
+ bool y_direction;
};
-} // end namespace
+} // namespace ocl
#endif
diff --git a/src/algo/clsurface.hpp b/src/algo/clsurface.hpp
index 241f7f8d..0a2f87ed 100644
--- a/src/algo/clsurface.hpp
+++ b/src/algo/clsurface.hpp
@@ -1,81 +1,66 @@
/* $Id$
- *
+ *
* Copyright (c) 2010-2011 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#ifndef CLSURFACE_H
#define CLSURFACE_H
-#include
#include
-#include
#include
+#include
+#include
-#include "point.hpp"
#include "halfedgediagram.hpp"
+#include "point.hpp"
+namespace ocl {
-namespace ocl
-{
-
-namespace clsurf
-{
-
-
-
-
-
-typedef boost::adjacency_list_traits::edge_descriptor CLSEdge;
+namespace clsurf {
+typedef boost::adjacency_list_traits::edge_descriptor
+ CLSEdge;
-typedef boost::adjacency_list_traits::vertex_descriptor CLSVertex;
-//typedef CLSGraph::Edge CLSEdge;
-//typedef CLSGraph::Vertex CLSVertex;
+typedef boost::adjacency_list_traits::vertex_descriptor
+ CLSVertex;
+// typedef CLSGraph::Edge CLSEdge;
+// typedef CLSGraph::Vertex CLSVertex;
typedef unsigned int CLSFace;
-//typedef hedi::HEDIGraph::Face CLSFace;
+// typedef hedi::HEDIGraph::Face CLSFace;
typedef std::vector CLSVertexVector;
typedef std::vector CLSFaceVector;
-typedef std::vector CLSEdgeVector;
-
+typedef std::vector CLSEdgeVector;
struct CLSVertexProps {
- CLSVertexProps() {
- init();
- }
+ CLSVertexProps() { init(); }
/// construct vertex at position p with type t
- CLSVertexProps( Point p) {
- position=p;
+ CLSVertexProps(Point p) {
+ position = p;
init();
}
void init() {
index = count;
count++;
}
-// HE data
- Point position; ///< the position of the vertex
- int index; ///< index of vertex
+ // HE data
+ Point position; ///< the position of the vertex
+ int index; ///< index of vertex
static int count; ///< global vertex count
};
@@ -84,42 +69,37 @@ int CLSVertexProps::count = 0;
struct CLSEdgeProps {
CLSEdgeProps() {}
/// create edge with given next, twin, and face
- CLSEdgeProps(CLSEdge n, CLSEdge t, CLSFace f) {
+ CLSEdgeProps(CLSEdge n, CLSEdge t, CLSFace f) {
next = n;
twin = t;
face = f;
}
CLSEdge next; ///< the next edge, counterclockwise, from this edge
CLSEdge twin; ///< the twin edge
- CLSFace face; ///< the face to which this edge belongs
+ CLSFace face; ///< the face to which this edge belongs
};
-/// properties of a face
+/// properties of a face
struct CLSFaceProps {
/// create face with given edge, generator, and type
CLSFaceProps() {}
- CLSFaceProps( CLSEdge e ) {
- edge = e;
- }
-
- CLSFace idx; ///< face index
- CLSEdge edge; ///< one edge that bounds this face
+ CLSFaceProps(CLSEdge e) { edge = e; }
+ CLSFace idx; ///< face index
+ CLSEdge edge; ///< one edge that bounds this face
};
-
// the cutter location surface graph
-typedef hedi::HEDIGraph< boost::listS, // out-edge storage
- boost::listS, // vertex set storage
- boost::bidirectionalS, // bidirectional graph.
- CLSVertexProps, // vertex properties
- CLSEdgeProps, // edge properties
- CLSFaceProps, // face properties
- boost::no_property, // graph properties
- boost::listS // edge storage
- > CLSGraph;
-
-
+typedef hedi::HEDIGraph
+ CLSGraph;
/// \brief cutter location surface.
///
@@ -141,156 +121,149 @@ typedef hedi::HEDIGraph< boost::listS, // out-edge storage
/// http://www.graphics.rwth-aachen.de/uploads/media/bommes_07_VMV_01.pdf
///
class CutterLocationSurface : public Operation {
- public:
- CutterLocationSurface() {
- far=1.0;
- init();
- }
- /// create diagram with given far-radius and number of bins
- CutterLocationSurface(double f) {
- far=f;
- init();
- }
- virtual ~CutterLocationSurface() {
- }
-
- void init() {
- // initialize cl-surf
- //
- // b e1 a
- // e2 e4
- // c e3 d
- CLSVertex a = g.add_vertex(); // VertexProps( Point(far,far,0) ), g);
- g[a].position = Point(far,far,0);
- CLSVertex b = g.add_vertex(); // VertexProps( Point(-far,far,0) ), g);
- g[b].position = Point(-far,far,0);
- CLSVertex c = g.add_vertex(); // VertexProps( Point(-far,-far,0) ), g);
- g[c].position = Point(-far,-far,0);
- CLSVertex d = g.add_vertex(); // VertexProps( Point(far,-far,0) ), g);
- g[c].position = Point(far,-far,0);
- CLSFace f_outer= g.add_face( );
- CLSFace f_inner= g.add_face( );
- CLSEdge e1 = g.add_edge(a , b );
- CLSEdge e1t = g.add_edge(b , a );
- CLSEdge e2 = g.add_edge(b , c );
- CLSEdge e2t = g.add_edge(c , b );
- CLSEdge e3 = g.add_edge(c , d );
- CLSEdge e3t = g.add_edge(d , c );
- CLSEdge e4 = g.add_edge(d , a );
- CLSEdge e4t = g.add_edge(a , d );
-
- g[f_inner].edge = e1;
- g[f_outer].edge = e1t;
- out_face = f_outer;
- // twin edges
- g.twin_edges(e1,e1t);
- g.twin_edges(e2,e2t);
- g.twin_edges(e3,e3t);
- g.twin_edges(e4,e4t);
- // inner face:
- g[e1].face = f_inner;
- g[e2].face = f_inner;
- g[e3].face = f_inner;
- g[e4].face = f_inner;
- // outer face:
- g[e1t].face = f_outer;
- g[e2t].face = f_outer;
- g[e3t].face = f_outer;
- g[e4t].face = f_outer;
- // next-pointers:
- g[e1].next = e2;
- g[e2].next = e3;
- g[e3].next = e4;
- g[e4].next = e1;
- // outer next-pointers:
- g[e1t].next = e4t;
- g[e4t].next = e3t;
- g[e3t].next = e2t;
- g[e2t].next = e1t;
-
- subdivide();
-
- }
-
- void subdivide() {
- for( CLSFace f=0; f< g.num_faces() ; ++f ) {
- // subdivide each face
- if ( f!= out_face ) {
- subdivide_face(f);
- }
- }
- }
-
- void subdivide_face(CLSFace f) {
- CLSEdgeVector f_edges = g.face_edges(f);
- assert( f_edges.size() == 4 );
- CLSVertex center = g.add_vertex();
- BOOST_FOREACH( CLSEdge e, f_edges ) {
- CLSVertex src = g.source(e);
- CLSVertex trg = g.target(e);
- // new vertex at mid-point of each edge
- Point mid = 0.5*(g[src].position+g[trg].position);
- g[center].position += 0.25*g[src].position; // average of four corners
- CLSVertex v = g.add_vertex();
- g[v].position = mid;
- g.insert_vertex_in_edge(v,e); // this also removes the old edges...
- }
- // now loop through edges again:
- f_edges = g.face_edges(f);
- assert( f_edges.size() == 8 );
- BOOST_FOREACH( CLSEdge e, f_edges ) {
- std::cout << e << "\n";
+ public:
+ CutterLocationSurface() {
+ far = 1.0;
+ init();
+ }
+ /// create diagram with given far-radius and number of bins
+ CutterLocationSurface(double f) {
+ far = f;
+ init();
+ }
+ virtual ~CutterLocationSurface() {}
+
+ void init() {
+ // initialize cl-surf
+ //
+ // b e1 a
+ // e2 e4
+ // c e3 d
+ CLSVertex a = g.add_vertex(); // VertexProps( Point(far,far,0) ), g);
+ g[a].position = Point(far, far, 0);
+ CLSVertex b = g.add_vertex(); // VertexProps( Point(-far,far,0) ), g);
+ g[b].position = Point(-far, far, 0);
+ CLSVertex c = g.add_vertex(); // VertexProps( Point(-far,-far,0) ), g);
+ g[c].position = Point(-far, -far, 0);
+ CLSVertex d = g.add_vertex(); // VertexProps( Point(far,-far,0) ), g);
+ g[c].position = Point(far, -far, 0);
+ CLSFace f_outer = g.add_face();
+ CLSFace f_inner = g.add_face();
+ CLSEdge e1 = g.add_edge(a, b);
+ CLSEdge e1t = g.add_edge(b, a);
+ CLSEdge e2 = g.add_edge(b, c);
+ CLSEdge e2t = g.add_edge(c, b);
+ CLSEdge e3 = g.add_edge(c, d);
+ CLSEdge e3t = g.add_edge(d, c);
+ CLSEdge e4 = g.add_edge(d, a);
+ CLSEdge e4t = g.add_edge(a, d);
+
+ g[f_inner].edge = e1;
+ g[f_outer].edge = e1t;
+ out_face = f_outer;
+ // twin edges
+ g.twin_edges(e1, e1t);
+ g.twin_edges(e2, e2t);
+ g.twin_edges(e3, e3t);
+ g.twin_edges(e4, e4t);
+ // inner face:
+ g[e1].face = f_inner;
+ g[e2].face = f_inner;
+ g[e3].face = f_inner;
+ g[e4].face = f_inner;
+ // outer face:
+ g[e1t].face = f_outer;
+ g[e2t].face = f_outer;
+ g[e3t].face = f_outer;
+ g[e4t].face = f_outer;
+ // next-pointers:
+ g[e1].next = e2;
+ g[e2].next = e3;
+ g[e3].next = e4;
+ g[e4].next = e1;
+ // outer next-pointers:
+ g[e1t].next = e4t;
+ g[e4t].next = e3t;
+ g[e3t].next = e2t;
+ g[e2t].next = e1t;
+
+ subdivide();
+ }
+
+ void subdivide() {
+ for (CLSFace f = 0; f < g.num_faces(); ++f) {
+ // subdivide each face
+ if (f != out_face) {
+ subdivide_face(f);
}
}
-
- virtual void run() {
+ }
+
+ void subdivide_face(CLSFace f) {
+ CLSEdgeVector f_edges = g.face_edges(f);
+ assert(f_edges.size() == 4);
+ CLSVertex center = g.add_vertex();
+ BOOST_FOREACH (CLSEdge e, f_edges) {
+ CLSVertex src = g.source(e);
+ CLSVertex trg = g.target(e);
+ // new vertex at mid-point of each edge
+ Point mid = 0.5 * (g[src].position + g[trg].position);
+ g[center].position += 0.25 * g[src].position; // average of four corners
+ CLSVertex v = g.add_vertex();
+ g[v].position = mid;
+ g.insert_vertex_in_edge(v, e); // this also removes the old edges...
}
- void setMinSampling(double s) {
- min_sampling=s;
+ // now loop through edges again:
+ f_edges = g.face_edges(f);
+ assert(f_edges.size() == 8);
+ BOOST_FOREACH (CLSEdge e, f_edges) {
+ std::cout << e << "\n";
}
-
+ }
+
+ virtual void run() {}
+ void setMinSampling(double s) { min_sampling = s; }
+
// PYTHON
- boost::python::list getVertices() {
- boost::python::list plist;
- BOOST_FOREACH( CLSVertex v, g.vertices() ) {
- plist.append( g[v].position );
- }
- return plist;
- }
-
- boost::python::list getEdges() {
- boost::python::list edge_list;
- BOOST_FOREACH( CLSEdge edge, g.edges() ) { // loop through each edge
- boost::python::list point_list; // the endpoints of each edge
- CLSVertex v1 = g.source( edge );
- CLSVertex v2 = g.target( edge );
- point_list.append( g[v1].position );
- point_list.append( g[v2].position );
- edge_list.append(point_list);
- }
- return edge_list;
+ boost::python::list getVertices() {
+ boost::python::list plist;
+ BOOST_FOREACH (CLSVertex v, g.vertices()) {
+ plist.append(g[v].position);
}
-
- /// string repr
- std::string str() const {
- std::ostringstream o;
- o << "CutterLocationSurface (nVerts="<< g.num_vertices() << " , nEdges="<< g.num_edges() <<"\n";
- return o.str();
+ return plist;
+ }
+
+ boost::python::list getEdges() {
+ boost::python::list edge_list;
+ BOOST_FOREACH (CLSEdge edge, g.edges()) { // loop through each edge
+ boost::python::list point_list; // the endpoints of each edge
+ CLSVertex v1 = g.source(edge);
+ CLSVertex v2 = g.target(edge);
+ point_list.append(g[v1].position);
+ point_list.append(g[v2].position);
+ edge_list.append(point_list);
}
+ return edge_list;
+ }
- protected:
-
+ /// string repr
+ std::string str() const {
+ std::ostringstream o;
+ o << "CutterLocationSurface (nVerts=" << g.num_vertices() << " , nEdges=" << g.num_edges() << "\n";
+ return o.str();
+ }
+
+ protected:
// DATA
- /// the half-edge diagram
- CLSGraph g;
- double min_sampling;
- double far;
- CLSFace out_face;
+ /// the half-edge diagram
+ CLSGraph g;
+ double min_sampling;
+ double far;
+ CLSFace out_face;
};
+} // namespace clsurf
-}// end clsurf namespace
-
-} // end ocl namespace
+} // namespace ocl
#endif
// end clsurface.h
diff --git a/src/algo/fiber.cpp b/src/algo/fiber.cpp
index cb34bc9e..f8145642 100644
--- a/src/algo/fiber.cpp
+++ b/src/algo/fiber.cpp
@@ -1,70 +1,69 @@
/* $Id$
- *
+ *
* Copyright (c) 2010-2011 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#include
#include "fiber.hpp"
-namespace ocl
-{
+namespace ocl {
Fiber::Fiber(const Point &p1in, const Point &p2in) {
- p1=p1in;
- p2=p2in;
+ p1 = p1in;
+ p2 = p2in;
calcDir();
}
void Fiber::calcDir() {
dir = p2 - p1;
- assert( dir.z == 0.0 );
+ assert(dir.z == 0.0);
dir.normalize();
}
-bool Fiber::contains(Interval& i) const {
- BOOST_FOREACH( Interval fi, ints) {
- if ( i.inside( fi ) )
+bool Fiber::contains(Interval &i) const {
+ BOOST_FOREACH (Interval fi, ints) {
+ if (i.inside(fi))
return true;
}
return false;
}
-bool Fiber::missing(Interval& i) const {
+bool Fiber::missing(Interval &i) const {
bool result = true;
- BOOST_FOREACH( Interval fi, ints) {
- if ( !i.outside( fi ) ) // all existing ints must be non-overlapping
- result = false;
+ BOOST_FOREACH (Interval fi, ints) {
+ if (!i.outside(fi)) // all existing ints must be non-overlapping
+ result = false;
}
return result;
}
-void Fiber::addInterval(Interval& i) {
+void Fiber::addInterval(Interval &i) {
if (i.empty())
return; // do nothing.
-
+
if (ints.empty()) { // empty fiber case
- ints.push_back(i);
+ ints.push_back(i);
return;
- } else if ( this->contains(i) ) { // if fiber already contains i
- return; // do nothing
- } else if ( this->missing(i) ) { // if fiber doesn't contain i
+ } else if (this->contains(i)) { // if fiber already contains i
+ return; // do nothing
+ } else if (this->missing(i)) { // if fiber doesn't contain i
ints.push_back(i);
return;
} else {
@@ -72,51 +71,51 @@ void Fiber::addInterval(Interval& i) {
std::vector::iterator itr;
itr = ints.begin();
std::vector overlaps;
- while (itr!=ints.end()) { // loop through all intervals
- if ( ! (itr->outside( i )) ) {
+ while (itr != ints.end()) { // loop through all intervals
+ if (!(itr->outside(i))) {
overlaps.push_back(*itr); // add overlaps here
- itr = ints.erase(itr); // erase overlaps from ints
+ itr = ints.erase(itr); // erase overlaps from ints
} else {
++itr;
}
}
overlaps.push_back(i);
// now build a new interval from i and the overlaps
- Interval sumint;
- BOOST_FOREACH(Interval intr, overlaps) {
- sumint.updateLower( intr.lower, intr.lower_cc );
- sumint.updateUpper( intr.upper, intr.upper_cc );
+ Interval sumint;
+ BOOST_FOREACH (Interval intr, overlaps) {
+ sumint.updateLower(intr.lower, intr.lower_cc);
+ sumint.updateUpper(intr.upper, intr.upper_cc);
}
ints.push_back(sumint); // add the sum-interval to ints
return;
}
}
-double Fiber::tval(Point& p) const {
+double Fiber::tval(Point &p) const {
// fiber is f = p1 + t * (p2-p1)
// t = (f-p1).dot(p2-p1) / (p2-p1).dot(p2-p1)
- return (p-p1).dot(p2-p1) / (p2-p1).dot(p2-p1);
+ return (p - p1).dot(p2 - p1) / (p2 - p1).dot(p2 - p1);
}
Point Fiber::point(double t) const {
- Point p = p1 + t*(p2-p1);
+ Point p = p1 + t * (p2 - p1);
return p;
}
void Fiber::printInts() const {
- int n=0;
- BOOST_FOREACH( Interval i, ints) {
- std::cout << n << ": [ " << i.lower << " , " << i.upper << " ]" << "\n";
+ int n = 0;
+ BOOST_FOREACH (Interval i, ints) {
+ std::cout << n << ": [ " << i.lower << " , " << i.upper << " ]"
+ << "\n";
++n;
}
}
-std::ostream& operator<<(std::ostream &stream, const Fiber& f) {
- stream << " fiber dir=" << f.dir << " and " << f.ints.size() << " intervals\n";
- stream << " fiber.p1=" << f.p1 << " fiber.p2 " << f.p2 ;
- return stream;
+std::ostream &operator<<(std::ostream &stream, const Fiber &f) {
+ stream << " fiber dir=" << f.dir << " and " << f.ints.size() << " intervals\n";
+ stream << " fiber.p1=" << f.p1 << " fiber.p2 " << f.p2;
+ return stream;
}
-
-} // end namespace
+} // namespace ocl
// end file fiber.cpp
diff --git a/src/algo/fiber.hpp b/src/algo/fiber.hpp
index bdcc24c7..4156a9d3 100644
--- a/src/algo/fiber.hpp
+++ b/src/algo/fiber.hpp
@@ -1,90 +1,85 @@
/* $Id$
- *
+ *
* Copyright (c) 2010-2011 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#ifndef FIBER_HPP
#define FIBER_HPP
#include
-#include "point.hpp"
#include "interval.hpp"
+#include "point.hpp"
-namespace ocl
-{
+namespace ocl {
/// a fiber is an infinite line in space along which the cutter can be pushed
/// into contact with a triangle. A Weave is built from many X-fibers and Y-fibers.
/// might be called a Dexel also in some papers/textbooks.
class Fiber {
- public:
- Fiber() {ints.clear();}
- /// create a Fiber between points p1 and p2
- Fiber(const Point &p1, const Point &p2);
- virtual ~Fiber() {}
- /// add an interval to this Fiber
- void addInterval(Interval& i);
- /// return true if Fiber already has interval i in it
- bool contains(Interval& i) const;
- /// return true if Interval i is completely missing (no overlaps) from Fiber
- bool missing(Interval& i) const;
-
- /// t-value corresponding to Point p
- double tval(Point& p) const;
- /// Point corresponding to t-value
- Point point(double t) const;
- /// print the intervals
- void printInts() const;
- /// return true if the Fiber contains no intervals
- bool empty() const {return ints.empty();}
- /// return number of intervals
- unsigned int size() const {return static_cast(ints.size());}
-
- /// return the upper cl-point of interval n
- Point upperCLPoint(unsigned int n) const {
- return point(ints[n].upper);
- }
- /// return the lower cl-point of interval n
- Point lowerCLPoint(unsigned int n) const {
- return point(ints[n].lower);
- }
-
- /// string repr
- friend std::ostream& operator<<(std::ostream &stream, const Fiber &f);
-
- bool operator==(const Fiber& other ) const {
- if( (this->p1 == other.p1) && (this->p2 == other.p2) )
- return true;
- else
- return false;
- }
+ public:
+ Fiber() { ints.clear(); }
+ /// create a Fiber between points p1 and p2
+ Fiber(const Point &p1, const Point &p2);
+ virtual ~Fiber() {}
+ /// add an interval to this Fiber
+ void addInterval(Interval &i);
+ /// return true if Fiber already has interval i in it
+ bool contains(Interval &i) const;
+ /// return true if Interval i is completely missing (no overlaps) from Fiber
+ bool missing(Interval &i) const;
+
+ /// t-value corresponding to Point p
+ double tval(Point &p) const;
+ /// Point corresponding to t-value
+ Point point(double t) const;
+ /// print the intervals
+ void printInts() const;
+ /// return true if the Fiber contains no intervals
+ bool empty() const { return ints.empty(); }
+ /// return number of intervals
+ unsigned int size() const { return static_cast(ints.size()); }
+
+ /// return the upper cl-point of interval n
+ Point upperCLPoint(unsigned int n) const { return point(ints[n].upper); }
+ /// return the lower cl-point of interval n
+ Point lowerCLPoint(unsigned int n) const { return point(ints[n].lower); }
+
+ /// string repr
+ friend std::ostream &operator<<(std::ostream &stream, const Fiber &f);
+
+ bool operator==(const Fiber &other) const {
+ if ((this->p1 == other.p1) && (this->p2 == other.p2))
+ return true;
+ else
+ return false;
+ }
// DATA
- Point p1; ///< start point
- Point p2; ///< end point
- Point dir; ///< direction vector (normalized)
- std::vector ints; ///< the intervals in this Fiber
- protected:
- /// set the direction(tangent) vector
- void calcDir();
+ Point p1; ///< start point
+ Point p2; ///< end point
+ Point dir; ///< direction vector (normalized)
+ std::vector ints; ///< the intervals in this Fiber
+ protected:
+ /// set the direction(tangent) vector
+ void calcDir();
};
-} // end namespace
+} // namespace ocl
#endif
// end file fiber.h
diff --git a/src/algo/fiberpushcutter.cpp b/src/algo/fiberpushcutter.cpp
index 3665859c..1f5a4bb6 100644
--- a/src/algo/fiberpushcutter.cpp
+++ b/src/algo/fiberpushcutter.cpp
@@ -1,37 +1,36 @@
/* $Id$
- *
+ *
* Copyright (c) 2010 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#include
-#ifdef _OPENMP
- #include
+#ifdef _OPENMP
+#include
#endif
+#include "fiberpushcutter.hpp"
#include "millingcutter.hpp"
#include "point.hpp"
#include "triangle.hpp"
-#include "fiberpushcutter.hpp"
-namespace ocl
-{
+namespace ocl {
//******** ********************** */
@@ -46,16 +45,14 @@ FiberPushCutter::FiberPushCutter() {
root = new KDTree();
}
-FiberPushCutter::~FiberPushCutter() {
- delete root;
-}
+FiberPushCutter::~FiberPushCutter() { delete root; }
void FiberPushCutter::setSTL(const STLSurf &s) {
surf = &s;
// std::cout << "BPC::setSTL() Building kd-tree... bucketSize=" << bucketSize << "..";
- root->setBucketSize( bucketSize );
+ root->setBucketSize(bucketSize);
if (x_direction)
- root->setYZDimensions();
+ root->setYZDimensions();
else if (y_direction)
root->setXZDimensions();
else {
@@ -67,41 +64,41 @@ void FiberPushCutter::setSTL(const STLSurf &s) {
// std::cout << " done.\n";
}
-void FiberPushCutter::pushCutter1(Fiber& f) {
+void FiberPushCutter::pushCutter1(Fiber &f) {
nCalls = 0;
- BOOST_FOREACH( const Triangle& t, surf->tris) {// test against all triangles in s
+ BOOST_FOREACH (const Triangle &t, surf->tris) { // test against all triangles in s
Interval i;
- cutter->pushCutter(f,i,t);
+ cutter->pushCutter(f, i, t);
f.addInterval(i);
++nCalls;
}
}
-void FiberPushCutter::pushCutter2(Fiber& f) {
- std::list::iterator it,it_end; // for looping over found triangles
- Interval* i;
- std::list* tris;
+void FiberPushCutter::pushCutter2(Fiber &f) {
+ std::list::iterator it, it_end; // for looping over found triangles
+ Interval *i;
+ std::list *tris;
CLPoint cl;
- if ( x_direction ) {
- cl.x=0;
- cl.y=f.p1.y;
- cl.z=f.p1.z;
- } else if (y_direction ) {
- cl.x=f.p1.x;
- cl.y=0;
- cl.z=f.p1.z;
+ if (x_direction) {
+ cl.x = 0;
+ cl.y = f.p1.y;
+ cl.z = f.p1.z;
+ } else if (y_direction) {
+ cl.x = f.p1.x;
+ cl.y = 0;
+ cl.z = f.p1.z;
}
tris = root->search_cutter_overlap(cutter, &cl);
it_end = tris->end();
- for ( it=tris->begin() ; it!=it_end ; ++it) {
- i = new Interval();
- cutter->pushCutter(f,*i,*it);
- f.addInterval(*i);
- ++nCalls;
- delete i;
+ for (it = tris->begin(); it != it_end; ++it) {
+ i = new Interval();
+ cutter->pushCutter(f, *i, *it);
+ f.addInterval(*i);
+ ++nCalls;
+ delete i;
}
- delete( tris );
+ delete (tris);
}
-}// end namespace
+} // namespace ocl
// end file fiberpushcutter.cpp
diff --git a/src/algo/fiberpushcutter.hpp b/src/algo/fiberpushcutter.hpp
index ed51db82..ffd8e42d 100644
--- a/src/algo/fiberpushcutter.hpp
+++ b/src/algo/fiberpushcutter.hpp
@@ -1,23 +1,23 @@
/* $Id$
- *
+ *
* Copyright (c) 2010 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#ifndef FIBERPUSHCUTTER_H
#define FIBERPUSHCUTTER_H
@@ -26,46 +26,50 @@
#include
#include
-#include "point.hpp"
#include "fiber.hpp"
#include "operation.hpp"
+#include "point.hpp"
-namespace ocl
-{
-
+namespace ocl {
///
/// \brief run push-cutter on a single input fiber
class FiberPushCutter : public Operation {
- public:
- FiberPushCutter();
- virtual ~FiberPushCutter();
-
- /// set the STL-surface and build kd-tree
- void setSTL(const STLSurf& s);
+ public:
+ FiberPushCutter();
+ virtual ~FiberPushCutter();
+
+ /// set the STL-surface and build kd-tree
+ void setSTL(const STLSurf &s);
+
+ /// set this bpc to be x-direction
+ void setXDirection() {
+ x_direction = true;
+ y_direction = false;
+ }
+ /// set this bpc to be Y-direction
+ void setYDirection() {
+ x_direction = false;
+ y_direction = true;
+ }
+ /// run() is an error.
+ void run() { assert(0); }
+ void run(Fiber &f) { pushCutter2(f); }
+
+ protected:
+ /// input fiber is tested against all triangles of surface
+ void pushCutter1(Fiber &f);
+ /// use kd-tree search to find overlapping triangles
+ void pushCutter2(Fiber &f);
- /// set this bpc to be x-direction
- void setXDirection() {x_direction=true;y_direction=false;}
- /// set this bpc to be Y-direction
- void setYDirection() {x_direction=false;y_direction=true;}
- /// run() is an error.
- void run() {assert(0);}
- void run(Fiber& f) {pushCutter2(f);}
-
- protected:
- /// input fiber is tested against all triangles of surface
- void pushCutter1(Fiber& f);
- /// use kd-tree search to find overlapping triangles
- void pushCutter2(Fiber& f);
-
// DATA
- /// true if this we have only x-direction fibers
- bool x_direction;
- /// true if we have y-direction fibers
- bool y_direction;
+ /// true if this we have only x-direction fibers
+ bool x_direction;
+ /// true if we have y-direction fibers
+ bool y_direction;
};
-} // end namespace
+} // namespace ocl
#endif
diff --git a/src/algo/interval.cpp b/src/algo/interval.cpp
index 3cea20f1..294ea9f4 100644
--- a/src/algo/interval.cpp
+++ b/src/algo/interval.cpp
@@ -1,23 +1,23 @@
/* $Id$
- *
+ *
* Copyright (c) 2010-2011 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#include
#include
@@ -25,93 +25,93 @@
#include "interval.hpp"
-namespace ocl
-{
+namespace ocl {
Interval::Interval() {
lower = 0.0;
upper = 0.0;
lower_cc = CCPoint();
upper_cc = CCPoint();
- in_weave=false;
+ in_weave = false;
}
Interval::Interval(const double l, const double u) {
- assert( l <= u );
+ assert(l <= u);
lower = l;
upper = u;
- in_weave=false;
+ in_weave = false;
}
-void Interval::update(const double t, CCPoint& p) {
- this->updateUpper(t,p);
- this->updateLower(t,p);
+void Interval::update(const double t, CCPoint &p) {
+ this->updateUpper(t, p);
+ this->updateLower(t, p);
}
-bool Interval::update_ifCCinEdgeAndTrue( double t_cl, CCPoint& cc_tmp, const Point& p1, const Point& p2, bool condition) {
- //if ( cc_tmp.isInsidePoints(p1,p2) && condition ) {
- if ( cc_tmp.isInside(p1,p2) && condition ) {
- update( t_cl , cc_tmp ); // both updateUpper(t,p) and updateLower(t,p)
- return true;
+bool Interval::update_ifCCinEdgeAndTrue(double t_cl, CCPoint &cc_tmp, const Point &p1, const Point &p2,
+ bool condition) {
+ // if ( cc_tmp.isInsidePoints(p1,p2) && condition ) {
+ if (cc_tmp.isInside(p1, p2) && condition) {
+ update(t_cl, cc_tmp); // both updateUpper(t,p) and updateLower(t,p)
+ return true;
} else {
return false;
}
}
-void Interval::updateUpper(const double t, CCPoint& p) {
+void Interval::updateUpper(const double t, CCPoint &p) {
if (upper_cc.type == NONE) {
upper = t;
lower = t;
- CCPoint* tmp = new CCPoint(p);
+ CCPoint *tmp = new CCPoint(p);
upper_cc = *tmp;
lower_cc = *tmp;
delete tmp;
}
- if ( t > upper ) {
+ if (t > upper) {
upper = t;
- CCPoint* tmp = new CCPoint(p);
+ CCPoint *tmp = new CCPoint(p);
upper_cc = *tmp;
delete tmp;
- }
+ }
}
-void Interval::updateLower(const double t, CCPoint& p) {
+void Interval::updateLower(const double t, CCPoint &p) {
if (lower_cc.type == NONE) {
lower = t;
upper = t;
- CCPoint* tmp = new CCPoint(p);
+ CCPoint *tmp = new CCPoint(p);
lower_cc = *tmp;
upper_cc = *tmp;
delete tmp;
}
- if ( t < lower ) {
- lower = t;
- CCPoint* tmp = new CCPoint(p);
+ if (t < lower) {
+ lower = t;
+ CCPoint *tmp = new CCPoint(p);
lower_cc = *tmp;
delete tmp;
}
}
// return true if *this is completely non-overlapping, or outside of i.
-bool Interval::outside(const Interval& i) const {
- if ( this->lower > i.upper )
+bool Interval::outside(const Interval &i) const {
+ if (this->lower > i.upper)
return true;
- else if ( this->upper < i.lower )
+ else if (this->upper < i.lower)
return true;
else
return false;
}
// return true if *this is contained within i
-bool Interval::inside(const Interval& i) const {
- if ( (this->lower > i.lower) && (this->upper < i.upper) )
+bool Interval::inside(const Interval &i) const {
+ if ((this->lower > i.lower) && (this->upper < i.upper))
return true;
else
return false;
}
bool Interval::empty() const {
- if ( lower==0.0 && upper==0.0 )
+ if (lower == 0.0 && upper == 0.0)
return true;
else
return false;
@@ -119,9 +119,9 @@ bool Interval::empty() const {
std::string Interval::str() const {
std::ostringstream o;
- o << "I ["<< lower <<" , " << upper << " ]";
+ o << "I [" << lower << " , " << upper << " ]";
return o.str();
}
-} // end namespace
+} // namespace ocl
// end file interval.cpp
diff --git a/src/algo/interval.hpp b/src/algo/interval.hpp
index ef4acfc3..1f8131ad 100644
--- a/src/algo/interval.hpp
+++ b/src/algo/interval.hpp
@@ -1,31 +1,31 @@
/* $Id$
- *
+ *
* Copyright (c) 2010-2011 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#ifndef INTERVAL_HPP
#define INTERVAL_HPP
#include
-//#include
+// #include
#include "ccpoint.hpp"
-//#include "weave_typedef.hpp"
+// #include "weave_typedef.hpp"
#include "halfedgediagram.hpp"
namespace ocl {
@@ -35,64 +35,59 @@ class Fiber;
/// interval for use by fiber and weave
/// a parameter interval [upper, lower]
class Interval {
- public:
- Interval();
- /// create and interval [l,u] (is this ever called??)
- Interval(const double l, const double u);
- virtual ~Interval() {};
-
- /// update upper with t, and corresponding cc-point p
- void updateUpper(const double t, CCPoint& p);
- /// update lower with t, and corresponding cc-point p
- void updateLower(const double t, CCPoint& p);
- /// call both updateUpper() and updateLower() with the given (t,p) pair
- void update(const double t, CCPoint& p);
- /// update interval with t_cl and cc_tmp if cc_tmp is in the p1-p2 edge and condition==true
- bool update_ifCCinEdgeAndTrue( double t_cl, CCPoint& cc_tmp, const Point& p1, const Point& p2, bool condition);
-
- /// return true if Interval i is outside *this
- bool outside(const Interval& i) const;
- /// return true if Interval i is inside *this
- bool inside(const Interval& i) const;
- /// return true if the interval is empty
- bool empty() const;
- /// string repr
- std::string str() const;
-
-
- CCPoint upper_cc; ///< cutter contact points at upper and lower are stored in upper_cc and lower_cc
- CCPoint lower_cc; ///< cutter contact point corresponding to lower
- double upper; ///< the upper t-value
- double lower; ///< the lower t-value
- bool in_weave; ///< flag for use by Weave::build()
- std::set::iterator> intersections_fibers; ///< fibers
-
- /// intersections with other intervals are stored in this set of
- /// VertexPairs of type std::pair
-
- typedef boost::adjacency_list_traits::vertex_descriptor WeaveVertex;
- typedef std::pair< WeaveVertex, double > VertexPair;
+ public:
+ Interval();
+ /// create and interval [l,u] (is this ever called??)
+ Interval(const double l, const double u);
+ virtual ~Interval(){};
- /// compare based on pair.second, the coordinate of the intersection
- struct VertexPairCompare {
- /// comparison operator
- bool operator() (const VertexPair& lhs, const VertexPair& rhs) const
- { return lhs.second < rhs.second ;}
- };
+ /// update upper with t, and corresponding cc-point p
+ void updateUpper(const double t, CCPoint &p);
+ /// update lower with t, and corresponding cc-point p
+ void updateLower(const double t, CCPoint &p);
+ /// call both updateUpper() and updateLower() with the given (t,p) pair
+ void update(const double t, CCPoint &p);
+ /// update interval with t_cl and cc_tmp if cc_tmp is in the p1-p2 edge and condition==true
+ bool update_ifCCinEdgeAndTrue(double t_cl, CCPoint &cc_tmp, const Point &p1, const Point &p2, bool condition);
- /// intersections stored in this set (for rapid finding of neighbors etc)
- typedef std::set< VertexPair, VertexPairCompare > VertexIntersectionSet;
-
- // this is the same type as ocl::weave::VertexPairIterator, but redefined here anywhere
- typedef VertexIntersectionSet::iterator VertexPairIterator;
+ /// return true if Interval i is outside *this
+ bool outside(const Interval &i) const;
+ /// return true if Interval i is inside *this
+ bool inside(const Interval &i) const;
+ /// return true if the interval is empty
+ bool empty() const;
+ /// string repr
+ std::string str() const;
-
- VertexIntersectionSet intersections2;
+ CCPoint upper_cc; ///< cutter contact points at upper and lower are stored in upper_cc and lower_cc
+ CCPoint lower_cc; ///< cutter contact point corresponding to lower
+ double upper; ///< the upper t-value
+ double lower; ///< the lower t-value
+ bool in_weave; ///< flag for use by Weave::build()
+ std::set::iterator> intersections_fibers; ///< fibers
+
+ /// intersections with other intervals are stored in this set of
+ /// VertexPairs of type std::pair
+
+ typedef boost::adjacency_list_traits::vertex_descriptor WeaveVertex;
+ typedef std::pair VertexPair;
+
+ /// compare based on pair.second, the coordinate of the intersection
+ struct VertexPairCompare {
+ /// comparison operator
+ bool operator()(const VertexPair &lhs, const VertexPair &rhs) const { return lhs.second < rhs.second; }
+ };
+
+ /// intersections stored in this set (for rapid finding of neighbors etc)
+ typedef std::set VertexIntersectionSet;
+
+ // this is the same type as ocl::weave::VertexPairIterator, but redefined here anywhere
+ typedef VertexIntersectionSet::iterator VertexPairIterator;
+
+ VertexIntersectionSet intersections2;
};
-} // end namespace
+} // namespace ocl
#endif
// end file interval.hpp
diff --git a/src/algo/operation.hpp b/src/algo/operation.hpp
index 9d942662..aa7ffc2f 100644
--- a/src/algo/operation.hpp
+++ b/src/algo/operation.hpp
@@ -1,23 +1,23 @@
/* $Id$
- *
+ *
* Copyright (c) 2010 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#ifndef OP_H
#define OP_H
@@ -26,12 +26,11 @@
#include
#include
-#include "point.hpp"
#include "fiber.hpp"
#include "kdtree.hpp"
+#include "point.hpp"
-namespace ocl
-{
+namespace ocl {
class STLSurf;
class Triangle;
@@ -41,102 +40,102 @@ class MillingCutter;
///
/// base-class for cam algorithms
class Operation {
- public:
- Operation() {}
- virtual ~Operation() {
- //std::cout << "~Operation()\n";
- }
- /// set the STL-surface and build kd-tree
- virtual void setSTL(const STLSurf& s) {
- surf = &s;
- BOOST_FOREACH(Operation* op, subOp) {
- op->setSTL(s);
- }
+ public:
+ Operation() {}
+ virtual ~Operation() {
+ // std::cout << "~Operation()\n";
+ }
+ /// set the STL-surface and build kd-tree
+ virtual void setSTL(const STLSurf &s) {
+ surf = &s;
+ BOOST_FOREACH (Operation *op, subOp) {
+ op->setSTL(s);
}
- /// set the MillingCutter to use
- virtual void setCutter(const MillingCutter* c) {
- cutter = c;
- BOOST_FOREACH(Operation* op, subOp) {
- op->setCutter(cutter);
- }
+ }
+ /// set the MillingCutter to use
+ virtual void setCutter(const MillingCutter *c) {
+ cutter = c;
+ BOOST_FOREACH (Operation *op, subOp) {
+ op->setCutter(cutter);
}
- /// set number of OpenMP threads. Defaults to OpenMP::omp_get_num_procs()
- void setThreads(unsigned int n) {
- nthreads = n;
- BOOST_FOREACH(Operation* op, subOp) {
- op->setThreads(nthreads);
- }
+ }
+ /// set number of OpenMP threads. Defaults to OpenMP::omp_get_num_procs()
+ void setThreads(unsigned int n) {
+ nthreads = n;
+ BOOST_FOREACH (Operation *op, subOp) {
+ op->setThreads(nthreads);
}
- /// return number of OpenMP threads
- int getThreads() const {return nthreads;}
- /// return the kd-tree bucket-size
- int getBucketSize() const {return bucketSize;}
- /// set the kd-tree bucket-size
- void setBucketSize(unsigned int s) {
- bucketSize = s;
- BOOST_FOREACH(Operation* op, subOp) {
- op->setBucketSize(bucketSize);
- }
+ }
+ /// return number of OpenMP threads
+ int getThreads() const { return nthreads; }
+ /// return the kd-tree bucket-size
+ int getBucketSize() const { return bucketSize; }
+ /// set the kd-tree bucket-size
+ void setBucketSize(unsigned int s) {
+ bucketSize = s;
+ BOOST_FOREACH (Operation *op, subOp) {
+ op->setBucketSize(bucketSize);
}
- /// return number of low-level calls
- int getCalls() const {return nCalls;}
-
- /// set the sampling interval for this Operation and all sub-operations
- virtual void setSampling(double s) {
- sampling=s;
- BOOST_FOREACH(Operation* op, subOp) {
- op->setSampling(sampling);
- }
- }
- /// return the sampling interval
- virtual double getSampling() {return sampling;}
-
- /// run the algorithm
- virtual void run() = 0;
- /// run algorithm on a single input CLPoint
- virtual void run(CLPoint& cl) {assert(0);}
- /// run push-cutter type algorithm on input Fiber
- virtual void run(Fiber& f) {assert(0);}
-
- virtual void reset() {}
-
- /// return CL-points
- virtual std::vector getCLPoints() {
- std::vector* clv = new std::vector();
- return *clv;
+ }
+ /// return number of low-level calls
+ int getCalls() const { return nCalls; }
+
+ /// set the sampling interval for this Operation and all sub-operations
+ virtual void setSampling(double s) {
+ sampling = s;
+ BOOST_FOREACH (Operation *op, subOp) {
+ op->setSampling(sampling);
}
- virtual void clearCLPoints() {}
-
- /// add an input CLPoint to this Operation
- virtual void appendPoint(CLPoint& p) {}
- /// used by batchpushcutter
- virtual void setXDirection() {}
- /// used by batchpushcutter
- virtual void setYDirection() {}
- /// add a fiber input to a push-cutter type operation
- virtual void appendFiber( Fiber& f ) {}
- /// return the result of a push-cutter type operation
- virtual std::vector* getFibers() const {return 0;}
-
- protected:
- /// sampling interval
- double sampling;
- /// how many low-level calls were made
- int nCalls;
- /// size of bucket-node in KD-tree
- unsigned int bucketSize;
- /// the MillingCutter used
- const MillingCutter* cutter;
- /// the STLSurf which we test against.
- const STLSurf* surf;
- /// root of a kd-tree
- KDTree* root;
- /// number of threads to use
- unsigned int nthreads;
- /// sub-operations, if any, of this operation
- std::vector subOp;
+ }
+ /// return the sampling interval
+ virtual double getSampling() { return sampling; }
+
+ /// run the algorithm
+ virtual void run() = 0;
+ /// run algorithm on a single input CLPoint
+ virtual void run(CLPoint &cl) { assert(0); }
+ /// run push-cutter type algorithm on input Fiber
+ virtual void run(Fiber &f) { assert(0); }
+
+ virtual void reset() {}
+
+ /// return CL-points
+ virtual std::vector getCLPoints() {
+ std::vector *clv = new std::vector();
+ return *clv;
+ }
+ virtual void clearCLPoints() {}
+
+ /// add an input CLPoint to this Operation
+ virtual void appendPoint(CLPoint &p) {}
+ /// used by batchpushcutter
+ virtual void setXDirection() {}
+ /// used by batchpushcutter
+ virtual void setYDirection() {}
+ /// add a fiber input to a push-cutter type operation
+ virtual void appendFiber(Fiber &f) {}
+ /// return the result of a push-cutter type operation
+ virtual std::vector *getFibers() const { return 0; }
+
+ protected:
+ /// sampling interval
+ double sampling;
+ /// how many low-level calls were made
+ int nCalls;
+ /// size of bucket-node in KD-tree
+ unsigned int bucketSize;
+ /// the MillingCutter used
+ const MillingCutter *cutter;
+ /// the STLSurf which we test against.
+ const STLSurf *surf;
+ /// root of a kd-tree
+ KDTree *root;
+ /// number of threads to use
+ unsigned int nthreads;
+ /// sub-operations, if any, of this operation
+ std::vector subOp;
};
-} // end namespace
+} // namespace ocl
#endif // end operation.h
diff --git a/src/algo/simple_weave.cpp b/src/algo/simple_weave.cpp
index 89ff2d57..96194af7 100644
--- a/src/algo/simple_weave.cpp
+++ b/src/algo/simple_weave.cpp
@@ -1,23 +1,23 @@
/* $Id$
- *
+ *
* Copyright (c) 2010-2011 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#include
#include
@@ -25,24 +25,23 @@
#include "simple_weave.hpp"
-namespace ocl
-{
+namespace ocl {
-namespace weave
-{
+namespace weave {
-std::pair SimpleWeave::find_neighbor_vertices( VertexPair v_pair, Interval& ival) {
- Interval::VertexPairIterator itr = ival.intersections2.lower_bound( v_pair ); // returns first that is not less than argument (equal or greater)
- assert( itr != ival.intersections2.end() ); // we must find a lower_bound
- Interval::VertexPairIterator v_above = itr; // lower_bound returns one beyond the give key, i.e. what we want
+std::pair SimpleWeave::find_neighbor_vertices(VertexPair v_pair, Interval &ival) {
+ Interval::VertexPairIterator itr =
+ ival.intersections2.lower_bound(v_pair); // returns first that is not less than argument (equal or greater)
+ assert(itr != ival.intersections2.end()); // we must find a lower_bound
+ Interval::VertexPairIterator v_above = itr; // lower_bound returns one beyond the give key, i.e. what we want
Interval::VertexPairIterator v_below = --itr; // this is the vertex below the give vertex
- std::pair out;
- out.first = v_above->first; // vertex above v (xu)
+ std::pair out;
+ out.first = v_above->first; // vertex above v (xu)
out.second = v_below->first; // vertex below v (xl)
- assert( out.first != out.second );
+ assert(out.first != out.second);
return out;
}
-
+
// from the list of fibers, build a graph
// FIXME: the problem here is that from N x-fibers and N y-fibers
// this builds a graph with roughly N*N vertices/edges. This consumes a lot of RAM even
@@ -61,147 +60,147 @@ void SimpleWeave::build() {
// xcl_lower <-> intp <-> xcl_upper
// if this connects points that are already connected, then remove old edge and
// provide this "via" connection
- //int n_xfiber=0;
+ // int n_xfiber=0;
// std::cout << " SimpleWeave::build()... \n";
- BOOST_FOREACH( Fiber& xf, xfibers) {
- assert( !xf.empty() ); // no empty fibers please
- BOOST_FOREACH( Interval& xi, xf.ints ) {
- //std::cout << "x-fiber " << n_xfiber++ << "\n";
+ BOOST_FOREACH (Fiber &xf, xfibers) {
+ assert(!xf.empty()); // no empty fibers please
+ BOOST_FOREACH (Interval &xi, xf.ints) {
+ // std::cout << "x-fiber " << n_xfiber++ << "\n";
double xmin = xf.point(xi.lower).x;
double xmax = xf.point(xi.upper).x;
- if ( (xmax-xmin) > 0) {
- assert( !xi.in_weave ); // this is the first time the x-interval is added!
- xi.in_weave = true;
- // add the X interval end-points to the weave
- Point p1( xf.point(xi.lower) );
- Vertex xv1 = add_cl_vertex( p1, xi, p1.x );
- Point p2( xf.point(xi.upper) );
- Vertex xv2 = add_cl_vertex( p2, xi, p2.x );
- Edge e1 = g.add_edge(xv1,xv2);
- Edge e2 = g.add_edge(xv2,xv1);
+ if ((xmax - xmin) > 0) {
+ assert(!xi.in_weave); // this is the first time the x-interval is added!
+ xi.in_weave = true;
+ // add the X interval end-points to the weave
+ Point p1(xf.point(xi.lower));
+ Vertex xv1 = add_cl_vertex(p1, xi, p1.x);
+ Point p2(xf.point(xi.upper));
+ Vertex xv2 = add_cl_vertex(p2, xi, p2.x);
+ Edge e1 = g.add_edge(xv1, xv2);
+ Edge e2 = g.add_edge(xv2, xv1);
+
+ // std::cout << " add_edge " << xv1 << "("<< p1.x<< ") - " << xv2 <<"("<< p2.x << ")\n";
+ g[e1].next = e2;
+ g[e2].next = e1;
+ g[e1].prev = e2;
+ g[e2].prev = e1;
+ // int n_yfiber=0;
+ BOOST_FOREACH (Fiber &yf, yfibers) { // loop through all y-fibers for all x-intervals
+ if ((xmin < yf.p1.x) && (yf.p1.x < xmax)) { // potential intersection between y-fiber and x-interval
+ BOOST_FOREACH (Interval &yi, yf.ints) {
+ // std::cout << "y-fiber " << n_yfiber++ << "\n";
+ double ymin = yf.point(yi.lower).y;
+ double ymax = yf.point(yi.upper).y;
+ if ((ymin < xf.p1.y) && (xf.p1.y < ymax)) {
+ // there is an actual intersection btw x-interval and y-interval
+ // X interval xi on fiber xf intersects with Y interval yi on fiber yf
+ // intersection is at ( yf.p1.x, xf.p1.y , xf.p1.z )
+ if (!yi.in_weave) { // add y-interval endpoints to weave
+ Point yp1(yf.point(yi.lower));
+ add_cl_vertex(yp1, yi, yp1.y);
+ Point yp2(yf.point(yi.upper));
+ add_cl_vertex(yp2, yi, yp2.y);
+ yi.in_weave = true;
+ }
+ // 3) intersection point, of type INT
+
+ Vertex v = g.null_vertex();
+
+ Point v_position(yf.p1.x, xf.p1.y, xf.p1.z);
+ // find neighbor to v
+ Vertex x_u, x_l;
+
+ // std::cout << " fins neighbor to x= " << v_position.x << "\n";
+ boost::tie(x_u, x_l) = find_neighbor_vertices(VertexPair(v, v_position.x), xi);
+ // std::cout << "found: x_u , x_l : " << x_u << " , " << x_l << "\n";
+ Vertex y_u, y_l;
+ boost::tie(y_u, y_l) = find_neighbor_vertices(VertexPair(v, v_position.y), yi);
- //std::cout << " add_edge " << xv1 << "("<< p1.x<< ") - " << xv2 <<"("<< p2.x << ")\n";
- g[e1].next = e2;
- g[e2].next = e1;
- g[e1].prev = e2;
- g[e2].prev = e1;
- //int n_yfiber=0;
- BOOST_FOREACH( Fiber& yf, yfibers ) { // loop through all y-fibers for all x-intervals
- if ( (xmin < yf.p1.x) && ( yf.p1.x < xmax ) ) {// potential intersection between y-fiber and x-interval
- BOOST_FOREACH( Interval& yi, yf.ints ) {
- //std::cout << "y-fiber " << n_yfiber++ << "\n";
- double ymin = yf.point(yi.lower).y ;
- double ymax = yf.point(yi.upper).y ;
- if ( (ymin < xf.p1.y) && (xf.p1.y < ymax) ) {
- // there is an actual intersection btw x-interval and y-interval
- // X interval xi on fiber xf intersects with Y interval yi on fiber yf
- // intersection is at ( yf.p1.x, xf.p1.y , xf.p1.z )
- if (!yi.in_weave) { // add y-interval endpoints to weave
- Point yp1( yf.point(yi.lower) );
- add_cl_vertex( yp1, yi, yp1.y );
- Point yp2( yf.point(yi.upper) );
- add_cl_vertex( yp2, yi, yp2.y );
- yi.in_weave = true;
- }
- // 3) intersection point, of type INT
-
- Vertex v = g.null_vertex();
-
- Point v_position( yf.p1.x, xf.p1.y , xf.p1.z );
- // find neighbor to v
- Vertex x_u, x_l;
-
- //std::cout << " fins neighbor to x= " << v_position.x << "\n";
- boost::tie( x_u, x_l ) = find_neighbor_vertices( VertexPair(v, v_position.x), xi );
- //std::cout << "found: x_u , x_l : " << x_u << " , " << x_l << "\n";
- Vertex y_u, y_l;
- boost::tie( y_u, y_l ) = find_neighbor_vertices( VertexPair(v, v_position.y), yi );
-
- //std::cout << "found: y_u , y_l : " << y_u << " , " << y_l << "\n";
-
- add_int_vertex(v_position,x_l,x_u,y_l,y_u,xi,yi);
- } // end intersection case
- } // end y interval loop
- } // end if(potential intersection)
- } // end y fiber loop
-
- // now we've added an x-interval, we've gone through all the y-intervals
- // if there isn't a single intersecting interval, then remove the x-interval as it is useless
- assert( xi.intersections2.size() >= 2 );
- if ( xi.intersections2.size() == 2 ) {
- clVertexSet.erase(xv1);
- clVertexSet.erase(xv2);
- g.clear_vertex(xv1);
- g.clear_vertex(xv2);
- g.remove_vertex(xv1);
- g.remove_vertex(xv2);
- }
-
- } // end zero-length interval check
+ // std::cout << "found: y_u , y_l : " << y_u << " , " << y_l << "\n";
+
+ add_int_vertex(v_position, x_l, x_u, y_l, y_u, xi, yi);
+ } // end intersection case
+ } // end y interval loop
+ } // end if(potential intersection)
+ } // end y fiber loop
+
+ // now we've added an x-interval, we've gone through all the y-intervals
+ // if there isn't a single intersecting interval, then remove the x-interval as it is useless
+ assert(xi.intersections2.size() >= 2);
+ if (xi.intersections2.size() == 2) {
+ clVertexSet.erase(xv1);
+ clVertexSet.erase(xv2);
+ g.clear_vertex(xv1);
+ g.clear_vertex(xv2);
+ g.remove_vertex(xv1);
+ g.remove_vertex(xv2);
+ }
+
+ } // end zero-length interval check
} // x interval loop
- } // end X-fiber loop
+ } // end X-fiber loop
}
// add a new CL-vertex to Weave, also adding it to the interval intersection-set, and to clVertices
-Vertex SimpleWeave::add_cl_vertex( const Point& position, Interval& ival, double ipos) {
- Vertex v = g.add_vertex();
+Vertex SimpleWeave::add_cl_vertex(const Point &position, Interval &ival, double ipos) {
+ Vertex v = g.add_vertex();
g[v].position = position;
g[v].type = CL;
- ival.intersections2.insert( VertexPair( v, ipos) ); // ?? this makes Interval depend on the WeaveGraph type
+ ival.intersections2.insert(VertexPair(v, ipos)); // ?? this makes Interval depend on the WeaveGraph type
clVertexSet.insert(v);
return v;
}
// add an internal vertex to the weave
-void SimpleWeave::add_int_vertex( const Point& v_position, // position of new vertex
- Vertex& x_l, // the x-lower vertex
- Vertex& x_u, // the x-upper vertex
- Vertex& y_l, // y-lower
- Vertex& y_u, // y-upper
- Interval& x_int, // the x-interval
- Interval& y_int ) // the y-interval
+void SimpleWeave::add_int_vertex(const Point &v_position, // position of new vertex
+ Vertex &x_l, // the x-lower vertex
+ Vertex &x_u, // the x-upper vertex
+ Vertex &y_l, // y-lower
+ Vertex &y_u, // y-upper
+ Interval &x_int, // the x-interval
+ Interval &y_int) // the y-interval
{
- //std::cout << " add_int_vertex " << "\n";
- Vertex v = g.add_vertex(); //hedi::add_vertex( VertexProps( v_position, INT ), g);
+ // std::cout << " add_int_vertex " << "\n";
+ Vertex v = g.add_vertex(); // hedi::add_vertex( VertexProps( v_position, INT ), g);
g[v].position = v_position;
g[v].type = INT;
- assert( g.has_edge(x_l,x_u) );
- assert( g.has_edge(x_u,x_l) );
- Edge xe_lu = g.edge(x_l,x_u);
- Edge xe_ul = g.edge(x_u,x_l);
+ assert(g.has_edge(x_l, x_u));
+ assert(g.has_edge(x_u, x_l));
+ Edge xe_lu = g.edge(x_l, x_u);
+ Edge xe_ul = g.edge(x_u, x_l);
Edge xe_lu_next = g[xe_lu].next;
- Edge xe_lu_prev = g[xe_lu].prev;
+ Edge xe_lu_prev = g[xe_lu].prev;
Edge xe_ul_next = g[xe_ul].next;
- Edge xe_ul_prev = g[xe_ul].prev;
-
+ Edge xe_ul_prev = g[xe_ul].prev;
+
// the next/prev data we need
- Edge ye_lu_next, ye_lu_prev ;
- Edge ye_ul_next, ye_ul_prev ;
+ Edge ye_lu_next, ye_lu_prev;
+ Edge ye_ul_next, ye_ul_prev;
Edge ye_lu, ye_ul;
- bool y_lu_edge = g.has_edge(y_l,y_u); // flag indicating existing y_l - y_u edge
+ bool y_lu_edge = g.has_edge(y_l, y_u); // flag indicating existing y_l - y_u edge
// the case where y_l and y_u are already connected.
- if ( y_lu_edge ) {
- assert( g.has_edge( y_u, y_l ) ); // twin must also exist
- ye_lu = g.edge( y_l, y_u);
- ye_ul = g.edge( y_u, y_l);
+ if (y_lu_edge) {
+ assert(g.has_edge(y_u, y_l)); // twin must also exist
+ ye_lu = g.edge(y_l, y_u);
+ ye_ul = g.edge(y_u, y_l);
ye_lu_next = g[ye_lu].next;
- ye_lu_prev = g[ye_lu].prev;
+ ye_lu_prev = g[ye_lu].prev;
ye_ul_next = g[ye_ul].next;
- ye_ul_prev = g[ye_ul].prev;
- }
+ ye_ul_prev = g[ye_ul].prev;
+ }
// and now eight new edges to add
- Edge xl_v = g.add_edge(x_l, v );
- Edge v_yl = g.add_edge(v , y_l);
- Edge yl_v = g.add_edge(y_l, v );
- Edge v_xu = g.add_edge(v , x_u);
- Edge xu_v = g.add_edge(x_u, v );
- Edge v_yu = g.add_edge(v , y_u);
- Edge yu_v = g.add_edge(y_u, v );
- Edge v_xl = g.add_edge(v , x_l);
+ Edge xl_v = g.add_edge(x_l, v);
+ Edge v_yl = g.add_edge(v, y_l);
+ Edge yl_v = g.add_edge(y_l, v);
+ Edge v_xu = g.add_edge(v, x_u);
+ Edge xu_v = g.add_edge(x_u, v);
+ Edge v_yu = g.add_edge(v, y_u);
+ Edge yu_v = g.add_edge(y_u, v);
+ Edge v_xl = g.add_edge(v, x_l);
// checks for special cases:
if (xe_lu_prev == xe_ul) // xl hairpin
xe_lu_prev = v_xl;
@@ -211,7 +210,7 @@ void SimpleWeave::add_int_vertex( const Point& v_position, // position of new v
xe_ul_prev = v_xu;
if (xe_ul_next == xe_lu)
xe_ul_next = xl_v;
- if ( y_lu_edge ) {
+ if (y_lu_edge) {
// the same checks for the y-edge
if (ye_lu_prev == ye_ul)
ye_lu_prev = v_yl;
@@ -228,35 +227,46 @@ void SimpleWeave::add_int_vertex( const Point& v_position, // position of new v
ye_ul_prev = v_yu;
}
// now set next/prev edges (there are 2*12=24 of these to do)
- g[xe_lu_prev].next = xl_v; g[xl_v].prev = xe_lu_prev;
- g[xl_v].next = v_yl; g[v_yl].prev = xl_v;
- g[v_yl].next = ye_ul_next; g[ye_ul_next].prev = v_yl;
- g[ye_lu_prev].next = yl_v; g[yl_v].prev = ye_lu_prev;
- g[yl_v].next = v_xu; g[v_xu].prev = yl_v;
- g[v_xu].next = xe_lu_next; g[xe_lu_next].prev = v_xu;
- g[xe_ul_prev].next = xu_v; g[xu_v].prev = xe_ul_prev;
- g[xu_v].next = v_yu; g[v_yu].prev = xu_v;
- g[v_yu].next = ye_lu_next; g[ye_lu_next].prev = v_yu;
- g[ye_ul_prev].next = yu_v; g[yu_v].prev = ye_ul_prev;
- g[yu_v].next = v_xl; g[v_xl].prev = yu_v;
- g[v_xl].next = xe_ul_next; g[xe_ul_next].prev = v_xl;
+ g[xe_lu_prev].next = xl_v;
+ g[xl_v].prev = xe_lu_prev;
+ g[xl_v].next = v_yl;
+ g[v_yl].prev = xl_v;
+ g[v_yl].next = ye_ul_next;
+ g[ye_ul_next].prev = v_yl;
+ g[ye_lu_prev].next = yl_v;
+ g[yl_v].prev = ye_lu_prev;
+ g[yl_v].next = v_xu;
+ g[v_xu].prev = yl_v;
+ g[v_xu].next = xe_lu_next;
+ g[xe_lu_next].prev = v_xu;
+ g[xe_ul_prev].next = xu_v;
+ g[xu_v].prev = xe_ul_prev;
+ g[xu_v].next = v_yu;
+ g[v_yu].prev = xu_v;
+ g[v_yu].next = ye_lu_next;
+ g[ye_lu_next].prev = v_yu;
+ g[ye_ul_prev].next = yu_v;
+ g[yu_v].prev = ye_ul_prev;
+ g[yu_v].next = v_xl;
+ g[v_xl].prev = yu_v;
+ g[v_xl].next = xe_ul_next;
+ g[xe_ul_next].prev = v_xl;
// delete the old x-edges
- g.remove_edge( x_l, x_u);
- g.remove_edge( x_u, x_l);
- if( y_lu_edge ) { // delete old y-edges
- assert( g.has_edge( y_l, y_u) );
- assert( g.has_edge( y_u, y_l) );
- g.remove_edge( y_l, y_u);
- g.remove_edge( y_u, y_l);
+ g.remove_edge(x_l, x_u);
+ g.remove_edge(x_u, x_l);
+ if (y_lu_edge) { // delete old y-edges
+ assert(g.has_edge(y_l, y_u));
+ assert(g.has_edge(y_u, y_l));
+ g.remove_edge(y_l, y_u);
+ g.remove_edge(y_u, y_l);
}
-
+
// finally add new intersection vertex to the interval sets
- x_int.intersections2.insert( VertexPair( v, v_position.x ) );
- y_int.intersections2.insert( VertexPair( v, v_position.y ) );
+ x_int.intersections2.insert(VertexPair(v, v_position.x));
+ y_int.intersections2.insert(VertexPair(v, v_position.y));
}
+} // namespace weave
-} // end weave namespace
-
-} // end ocl namespace
+} // namespace ocl
// end file simple_weave.cpp
diff --git a/src/algo/simple_weave.hpp b/src/algo/simple_weave.hpp
index 491835d4..f3c2a563 100644
--- a/src/algo/simple_weave.hpp
+++ b/src/algo/simple_weave.hpp
@@ -1,23 +1,23 @@
/* $Id$
- *
+ *
* Copyright (c) 2010-2011 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#ifndef SIMPLE_WEAVE_HPP
#define SIMPLE_WEAVE_HPP
@@ -30,35 +30,30 @@ namespace ocl {
namespace weave {
class SimpleWeave : public Weave {
- public:
- SimpleWeave() {}
- virtual ~SimpleWeave() {}
- void build();
- protected:
-
- /// add CL vertex to weave
- /// sets position, type, and inserts the VertexPair into Interval::intersections
- /// also adds the CL-vertex to clVertices, a list of cl-verts to be processed during face_traverse()
- Vertex add_cl_vertex( const Point& position, Interval& interv, double ipos);
-
- /// add INT vertex to weave
- /// the new vertex at v_position has neighbor vertices x_lower and x_upper in the x-direction on interval xi
- /// and y_lower, y_upper in the y-direction of interval yi
- /// Create new edges and delete old ones
- void add_int_vertex( const Point& v_position,
- Vertex& x_l,
- Vertex& x_u,
- Vertex& y_l,
- Vertex& y_u,
- Interval& xi,
- Interval& yi );
-
- /// given a vertex in the graph, find its upper and lower neighbor vertices
- std::pair find_neighbor_vertices( VertexPair v_pair, Interval& ival);
+ public:
+ SimpleWeave() {}
+ virtual ~SimpleWeave() {}
+ void build();
+
+ protected:
+ /// add CL vertex to weave
+ /// sets position, type, and inserts the VertexPair into Interval::intersections
+ /// also adds the CL-vertex to clVertices, a list of cl-verts to be processed during face_traverse()
+ Vertex add_cl_vertex(const Point &position, Interval &interv, double ipos);
+
+ /// add INT vertex to weave
+ /// the new vertex at v_position has neighbor vertices x_lower and x_upper in the x-direction on interval xi
+ /// and y_lower, y_upper in the y-direction of interval yi
+ /// Create new edges and delete old ones
+ void add_int_vertex(const Point &v_position, Vertex &x_l, Vertex &x_u, Vertex &y_l, Vertex &y_u, Interval &xi,
+ Interval &yi);
+
+ /// given a vertex in the graph, find its upper and lower neighbor vertices
+ std::pair find_neighbor_vertices(VertexPair v_pair, Interval &ival);
};
-} // end weave namespace
+} // namespace weave
-} // end ocl namespace
+} // namespace ocl
#endif
// end file simple_weave.hpp
diff --git a/src/algo/smart_weave.cpp b/src/algo/smart_weave.cpp
index a57dca0a..bc642e62 100644
--- a/src/algo/smart_weave.cpp
+++ b/src/algo/smart_weave.cpp
@@ -1,23 +1,23 @@
/* $Id$
- *
+ *
* Copyright (c) 2010-2011 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#include
#include
@@ -25,63 +25,61 @@
#include "smart_weave.hpp"
-namespace ocl
-{
+namespace ocl {
-namespace weave
-{
+namespace weave {
// given a VertexPair and an Interval, in the Interval find the Vertex above and below the given vertex
-std::pair SmartWeave::find_neighbor_vertices( VertexPair v_pair, Interval& ival, bool above_equality ) {
- Interval::VertexPairIterator itr = ival.intersections2.lower_bound( v_pair ); // returns first that is not less than argument (equal or greater)
- assert( itr != ival.intersections2.end() ); // we must find a lower_bound
- Interval::VertexPairIterator v_above;
- if ( above_equality )
+std::pair SmartWeave::find_neighbor_vertices(VertexPair v_pair, Interval &ival, bool above_equality) {
+ Interval::VertexPairIterator itr =
+ ival.intersections2.lower_bound(v_pair); // returns first that is not less than argument (equal or greater)
+ assert(itr != ival.intersections2.end()); // we must find a lower_bound
+ Interval::VertexPairIterator v_above;
+ if (above_equality)
v_above = itr; // lower_bound returns one beyond the give key, i.e. what we want
else {
v_above = ++itr;
--itr;
}
Interval::VertexPairIterator v_below = --itr; // this is the vertex below the given vertex
- std::pair out;
- out.first = v_above->first; // vertex above v (xu)
+ std::pair out;
+ out.first = v_above->first; // vertex above v (xu)
out.second = v_below->first; // vertex below v (xl)
return out;
}
-
// this is the new smarter build() which uses less RAM
void SmartWeave::build() {
std::cout << " SimpleWeave::build()... \n";
-
+
// this adds all CL-vertices from x-intervals
// it also populates the xi.intersections_fibers set of intersecting y-fibers
// also add the first-crossing vertex and the last-crossing vertex
-
- //std::cout << " build2() add_vertices_x() ... " << std::flush ;
+
+ // std::cout << " build2() add_vertices_x() ... " << std::flush ;
add_vertices_x();
- //std::cout << " done.\n" << std::flush ;
- // the same for y-intervals, add all CL-points, and intersections to the set.
- //std::cout << " build2() add_vertices_y() ... " << std::flush ;
+ // std::cout << " done.\n" << std::flush ;
+ // the same for y-intervals, add all CL-points, and intersections to the set.
+ // std::cout << " build2() add_vertices_y() ... " << std::flush ;
add_vertices_y();
- //std::cout << " done.\n" << std::flush ;
-
- //std::cout << " build2() looping over xfibers ... " << std::flush ;
- BOOST_FOREACH( Fiber& xf, xfibers ) {
+ // std::cout << " done.\n" << std::flush ;
+
+ // std::cout << " build2() looping over xfibers ... " << std::flush ;
+ BOOST_FOREACH (Fiber &xf, xfibers) {
std::vector::iterator xi;
- for( xi = xf.ints.begin(); xi < xf.ints.end(); xi++ ) {
+ for (xi = xf.ints.begin(); xi < xf.ints.end(); xi++) {
std::set::iterator>::const_iterator current, prev;
- if( xi->intersections_fibers.size() > 1 ) {
+ if (xi->intersections_fibers.size() > 1) {
current = xi->intersections_fibers.begin();
prev = current++;
- for( ; current != xi->intersections_fibers.end(); current++ ) {
+ for (; current != xi->intersections_fibers.end(); current++) {
// for each x-interval, loop through the intersecting y-fibers
- if( (*current - *prev) > 1 ) {
- std::vector::iterator yi = find_interval_crossing_x( xf, *(*prev + 1) );
- add_vertex( xf, *(*prev + 1), xi , yi, FULLINT );
- if( (*current - *prev) > 2 ) {
- yi = find_interval_crossing_x( xf, *(*current - 1) );
- add_vertex( xf, *(*current - 1), xi, yi, FULLINT );
+ if ((*current - *prev) > 1) {
+ std::vector::iterator yi = find_interval_crossing_x(xf, *(*prev + 1));
+ add_vertex(xf, *(*prev + 1), xi, yi, FULLINT);
+ if ((*current - *prev) > 2) {
+ yi = find_interval_crossing_x(xf, *(*current - 1));
+ add_vertex(xf, *(*current - 1), xi, yi, FULLINT);
}
}
prev = current;
@@ -89,28 +87,29 @@ void SmartWeave::build() {
}
}
}
- //std::cout << " done.\n" << std::flush ;
-
- //std::cout << " build2() looping over yfibers ... " << std::flush ;
- //std::cout << yfibers.size() << " fibers to loop over \n"<< std::flush ;
- //int ny = 0;
- BOOST_FOREACH( Fiber& yf, yfibers ) {
- //std::cout << " fiber nr: " << ny++ << " has " << yf.ints.size() << " intervals\n" << std::flush ;
+ // std::cout << " done.\n" << std::flush ;
+
+ // std::cout << " build2() looping over yfibers ... " << std::flush ;
+ // std::cout << yfibers.size() << " fibers to loop over \n"<< std::flush ;
+ // int ny = 0;
+ BOOST_FOREACH (Fiber &yf, yfibers) {
+ // std::cout << " fiber nr: " << ny++ << " has " << yf.ints.size() << " intervals\n" << std::flush ;
std::vector::iterator yi;
- //int ny_int=0;
- for( yi = yf.ints.begin(); yi < yf.ints.end(); yi++ ) {
- //std::cout << " interval nr: " << ny_int++ << " has yi->intersections_fibers.size()= " << yi->intersections_fibers.size() << "\n" << std::flush;
+ // int ny_int=0;
+ for (yi = yf.ints.begin(); yi < yf.ints.end(); yi++) {
+ // std::cout << " interval nr: " << ny_int++ << " has yi->intersections_fibers.size()= " <<
+ // yi->intersections_fibers.size() << "\n" << std::flush;
std::set::iterator>::iterator current, prev;
- if( yi->intersections_fibers.size() > 1 ) {
+ if (yi->intersections_fibers.size() > 1) {
current = yi->intersections_fibers.begin();
prev = current++;
- for( ; current != yi->intersections_fibers.end(); current++ ) {
- if( (*current - *prev) > 1 ) {
- std::vector::iterator xi = find_interval_crossing_y( *(*prev + 1), yf );
- add_vertex( *(*prev + 1), yf, xi , yi, FULLINT );
- if( (*current - *prev) > 2 ) {
- xi = find_interval_crossing_y( *(*current - 1), yf );
- add_vertex( *(*current - 1), yf, xi, yi, FULLINT );
+ for (; current != yi->intersections_fibers.end(); current++) {
+ if ((*current - *prev) > 1) {
+ std::vector::iterator xi = find_interval_crossing_y(*(*prev + 1), yf);
+ add_vertex(*(*prev + 1), yf, xi, yi, FULLINT);
+ if ((*current - *prev) > 2) {
+ xi = find_interval_crossing_y(*(*current - 1), yf);
+ add_vertex(*(*current - 1), yf, xi, yi, FULLINT);
}
}
prev = current;
@@ -118,251 +117,249 @@ void SmartWeave::build() {
}
}
}
- //std::cout << " done.\n" << std::flush ;
-
+ // std::cout << " done.\n" << std::flush ;
+
// std::cout << " SmartWeave::build() add_all_edges()... " << std::flush ;
add_all_edges();
// std::cout << " done.\n" << std::flush ;
}
// add a new CL-vertex to Weave, also adding it to the interval intersection-set, and to clVertices
-Vertex SmartWeave::add_cl_vertex( const Point& position, Interval& ival, double ipos) {
- Vertex v = g.add_vertex();
+Vertex SmartWeave::add_cl_vertex(const Point &position, Interval &ival, double ipos) {
+ Vertex v = g.add_vertex();
g[v].position = position;
g[v].type = CL;
- ival.intersections2.insert( VertexPair( v, ipos) ); // ?? this makes Interval depend on the WeaveGraph type
+ ival.intersections2.insert(VertexPair(v, ipos)); // ?? this makes Interval depend on the WeaveGraph type
clVertexSet.insert(v);
return v;
}
void SmartWeave::add_vertices_x() {
std::vector::iterator xf;
- for( xf = xfibers.begin(); xf < xfibers.end(); xf++ ) {
+ for (xf = xfibers.begin(); xf < xfibers.end(); xf++) {
std::vector::iterator xi;
- for( xi = xf->ints.begin(); xi < xf->ints.end(); xi++ ) {
+ for (xi = xf->ints.begin(); xi < xf->ints.end(); xi++) {
// find first and last fiber crossing this interval
std::vector::iterator yf = yfibers.begin();
std::vector::iterator yi;
- bool is_crossing = crossing_x( *yf, yi, *xi, *xf );
- while( (yfpoint( xi->lower ) );
- add_cl_vertex( lower, *xi, lower.x );
- Point upper( xf->point( xi->upper ) );
- add_cl_vertex( upper, *xi, upper.x );
+ if (yf < yfibers.end()) {
+ Point lower(xf->point(xi->lower));
+ add_cl_vertex(lower, *xi, lower.x);
+ Point upper(xf->point(xi->upper));
+ add_cl_vertex(upper, *xi, upper.x);
- add_vertex( *xf, *yf, xi, yi, INT ); // the first crossing vertex
- xi->intersections_fibers.insert( yf );
- yi->intersections_fibers.insert( xf );
+ add_vertex(*xf, *yf, xi, yi, INT); // the first crossing vertex
+ xi->intersections_fibers.insert(yf);
+ yi->intersections_fibers.insert(xf);
- is_crossing = crossing_x( *yf, yi, *xi, *xf );
- while( (yfintersections_fibers.insert( yf );
- yi->intersections_fibers.insert( xf );
+ add_vertex(*xf, *(--yf), xi, yi, INT); // the last crossing vertex
+ xi->intersections_fibers.insert(yf);
+ yi->intersections_fibers.insert(xf);
}
- }// end foreach x-interval
- }// end foreach x-fiber
+ } // end foreach x-interval
+ } // end foreach x-fiber
}
void SmartWeave::add_vertices_y() {
std::vector::iterator yf;
- for( yf = yfibers.begin(); yf < yfibers.end(); yf++ ) {
+ for (yf = yfibers.begin(); yf < yfibers.end(); yf++) {
std::vector::iterator yi;
- for( yi = yf->ints.begin(); yi < yf->ints.end(); yi++ ) {
+ for (yi = yf->ints.begin(); yi < yf->ints.end(); yi++) {
std::vector::iterator xf = xfibers.begin();
std::vector::iterator xi;
-
+
// find first and last fiber crossing this interval
- bool is_crossing = crossing_y( *xf, xi, *yi, *yf );
- while ( (xfpoint( yi->lower ) );
- add_cl_vertex( lower, *yi, lower.y );
- Point upper( yf->point( yi->upper ) );
- add_cl_vertex( upper, *yi, upper.y );
+ if (xf < xfibers.end()) {
+ Point lower(yf->point(yi->lower));
+ add_cl_vertex(lower, *yi, lower.y);
+ Point upper(yf->point(yi->upper));
+ add_cl_vertex(upper, *yi, upper.y);
- if( add_vertex( *xf, *yf, xi, yi, INT ) ) { // add_vertex returns false if vertex already exists
- xi->intersections_fibers.insert( yf );
- yi->intersections_fibers.insert( xf );
+ if (add_vertex(*xf, *yf, xi, yi, INT)) { // add_vertex returns false if vertex already exists
+ xi->intersections_fibers.insert(yf);
+ yi->intersections_fibers.insert(xf);
}
- bool is_crossing = crossing_y( *xf, xi, *yi, *yf );
- while ( (xfintersections_fibers.insert( yf );
- yi->intersections_fibers.insert( xf );
+ if (add_vertex(*(--xf), *yf, xi, yi, INT)) {
+ xi->intersections_fibers.insert(yf);
+ yi->intersections_fibers.insert(xf);
}
}
- }// end foreach x-interval
- }// end foreach x-fiber
+ } // end foreach x-interval
+ } // end foreach x-fiber
}
-//crossing_x fiber
-bool SmartWeave::crossing_x( Fiber& yf, std::vector::iterator& yi, Interval& xi, Fiber& xf ) {
- //if the FIBER crosses the xi interval
- if( (yf.p1.x >= xf.point( xi.lower ).x) && (yf.p1.x <= xf.point( xi.upper ).x) ) {
- //for all the intervals of this y-fiber...
+// crossing_x fiber
+bool SmartWeave::crossing_x(Fiber &yf, std::vector::iterator &yi, Interval &xi, Fiber &xf) {
+ // if the FIBER crosses the xi interval
+ if ((yf.p1.x >= xf.point(xi.lower).x) && (yf.p1.x <= xf.point(xi.upper).x)) {
+ // for all the intervals of this y-fiber...
std::vector::iterator it;
- for( it = yf.ints.begin(); it < yf.ints.end(); it++ ) {
- //find the first INTERVAL which crosses our xi interval
- if( (yf.point( it->lower ).y <= xf.p1.y) && (yf.point( it->upper ).y >= xf.p1.y) ) {
- //save the y-interval iterator
- //and return true because we found an interval
+ for (it = yf.ints.begin(); it < yf.ints.end(); it++) {
+ // find the first INTERVAL which crosses our xi interval
+ if ((yf.point(it->lower).y <= xf.p1.y) && (yf.point(it->upper).y >= xf.p1.y)) {
+ // save the y-interval iterator
+ // and return true because we found an interval
yi = it;
return true;
}
}
- //return false, there is no y-interval on this y-fiber crossing our xi interval
+ // return false, there is no y-interval on this y-fiber crossing our xi interval
return false;
}
- //this y-fiber doesn't cross our xi interval
- else
+ // this y-fiber doesn't cross our xi interval
+ else
return false;
}
-//crossing_y fiber
-bool SmartWeave::crossing_y( Fiber& xf, std::vector::iterator& xi, Interval& yi, Fiber& yf ) {
- if( (xf.p1.y >= yf.point( yi.lower ).y) && (xf.p1.y <= yf.point( yi.upper ).y) ) {
+// crossing_y fiber
+bool SmartWeave::crossing_y(Fiber &xf, std::vector::iterator &xi, Interval &yi, Fiber &yf) {
+ if ((xf.p1.y >= yf.point(yi.lower).y) && (xf.p1.y <= yf.point(yi.upper).y)) {
std::vector::iterator it;
- for( it = xf.ints.begin(); it < xf.ints.end(); it++ ) {
- if( (xf.point( it->lower ).x <= yf.p1.x) && (xf.point( it->upper ).x >= yf.p1.x) ) {
+ for (it = xf.ints.begin(); it < xf.ints.end(); it++) {
+ if ((xf.point(it->lower).x <= yf.p1.x) && (xf.point(it->upper).x >= yf.p1.x)) {
xi = it;
return true;
}
}
return false;
- }
- else
+ } else
return false;
}
-//find_interval_crossing_x
-std::vector::iterator SmartWeave::find_interval_crossing_x( Fiber& xf, Fiber& yf ) {
+// find_interval_crossing_x
+std::vector::iterator SmartWeave::find_interval_crossing_x(Fiber &xf, Fiber &yf) {
std::vector::iterator yi, xi;
yi = yf.ints.begin();
- while( (yi::iterator SmartWeave::find_interval_crossing_y( Fiber& xf, Fiber& yf ) {
+// crossing_y interval
+std::vector::iterator SmartWeave::find_interval_crossing_y(Fiber &xf, Fiber &yf) {
std::vector::iterator xi, yi;
xi = xf.ints.begin();
- while( (xi::iterator xi,
- std::vector::iterator yi,
- enum VertexType type ) {
- //test if vertex exists
- BOOST_FOREACH( std::vector::iterator it_xf, yi->intersections_fibers ) {
- if( *it_xf == xf )
+// add_vertex
+bool SmartWeave::add_vertex(Fiber &xf, Fiber &yf, std::vector::iterator xi,
+ std::vector::iterator yi, enum VertexType type) {
+ // test if vertex exists
+ BOOST_FOREACH (std::vector::iterator it_xf, yi->intersections_fibers) {
+ if (*it_xf == xf)
return false;
}
- Point v_position( yf.p1.x, xf.p1.y, xf.p1.z );
- Vertex v =g.add_vertex();
+ Point v_position(yf.p1.x, xf.p1.y, xf.p1.z);
+ Vertex v = g.add_vertex();
g[v].position = v_position;
g[v].type = type;
- g[v].xi= xi;
- g[v].yi= yi;
- xi->intersections2.insert( VertexPair( v, v_position.x ) );
- yi->intersections2.insert( VertexPair( v, v_position.y ) );
+ g[v].xi = xi;
+ g[v].yi = yi;
+ xi->intersections2.insert(VertexPair(v, v_position.x));
+ yi->intersections2.insert(VertexPair(v, v_position.y));
return true;
}
-//add_all_edges
-void SmartWeave::add_all_edges()
-{
- std::vector vertices = g.vertices();
+// add_all_edges
+void SmartWeave::add_all_edges() {
+ std::vector vertices = g.vertices();
std::cout << "There are " << vertices.size() << " vertices.\n";
- BOOST_FOREACH( Vertex& vertex, vertices ) {
- if( (g[vertex].type == INT) || (g[vertex].type == FULLINT) ) {
- std::vector adjacent_vertices;
- std::vector::iterator adj_itr;
- std::vector in_edges, out_edges;
- std::vector::iterator in_edge_itr, out_edge_itr;
+ BOOST_FOREACH (Vertex &vertex, vertices) {
+ if ((g[vertex].type == INT) || (g[vertex].type == FULLINT)) {
+ std::vector adjacent_vertices;
+ std::vector::iterator adj_itr;
+ std::vector in_edges, out_edges;
+ std::vector::iterator in_edge_itr, out_edge_itr;
Vertex x_u, x_l, y_u, y_l;
- boost::tie( x_u, x_l ) = find_neighbor_vertices( VertexPair(vertex, g[vertex].position.x), *(g[vertex].xi), false );
- boost::tie( y_u, y_l ) = find_neighbor_vertices( VertexPair(vertex, g[vertex].position.y), *(g[vertex].yi), false );
-
- adjacent_vertices.push_back( x_l );
- adjacent_vertices.push_back( y_u );
- adjacent_vertices.push_back( x_u );
- adjacent_vertices.push_back( y_l );
-
- for( adj_itr=adjacent_vertices.begin(); adj_itr adjacent_vertices;
Vertex x_u, x_l, y_u, y_l;
- boost::tie( x_u, x_l ) = find_neighbor_vertices( VertexPair(vertex, g[vertex].position.x), *(g[vertex].xi), false );
- boost::tie( y_u, y_l ) = find_neighbor_vertices( VertexPair(vertex, g[vertex].position.y), *(g[vertex].yi), false );
+ boost::tie( x_u, x_l ) = find_neighbor_vertices( VertexPair(vertex, g[vertex].position.x), *(g[vertex].xi),
+ false ); boost::tie( y_u, y_l ) = find_neighbor_vertices( VertexPair(vertex, g[vertex].position.y),
+ *(g[vertex].yi), false );
if( g[x_l].type == INT ) adjacent_vertices.push_back( x_l );
if( g[y_u].type == INT ) adjacent_vertices.push_back( y_u );
if( g[x_u].type == INT ) adjacent_vertices.push_back( x_u );
if( g[y_l].type == INT ) adjacent_vertices.push_back( y_l );
-
+
if( adjacent_vertices.size() == 1 ) {
Edge in, out;
std::vector::iterator adj_itr = adjacent_vertices.begin();
@@ -384,7 +381,7 @@ void SmartWeave::add_all_edges()
std::vector::iterator edge_itr;
for( adj_itr=adjacent_vertices.begin(); adj_itr.
-*/
+ */
#ifndef SMART_WEAVE_HPP
#define SMART_WEAVE_HPP
@@ -30,29 +30,27 @@ namespace ocl {
namespace weave {
class SmartWeave : public Weave {
- public:
- SmartWeave() {}
- virtual ~SmartWeave() {}
- void build();
- protected:
- void add_vertices_x();
- void add_vertices_y();
- bool crossing_x( Fiber& yf, std::vector::iterator& yi, Interval& xi, Fiber& xf );
- bool crossing_y( Fiber& xf, std::vector::iterator& xi, Interval& yi, Fiber& yf );
- std::vector::iterator find_interval_crossing_x( Fiber& xf, Fiber& yf );
- std::vector::iterator find_interval_crossing_y( Fiber& xf, Fiber& yf );
- Vertex add_cl_vertex( const Point& position, Interval& ival, double ipos);
- bool add_vertex( Fiber& xf,
- Fiber& yf,
- std::vector::iterator xi,
- std::vector::iterator yi,
- enum VertexType type );
- void add_all_edges();
- std::pair find_neighbor_vertices( VertexPair v_pair, Interval& ival, bool above_equality );
+ public:
+ SmartWeave() {}
+ virtual ~SmartWeave() {}
+ void build();
+
+ protected:
+ void add_vertices_x();
+ void add_vertices_y();
+ bool crossing_x(Fiber &yf, std::vector::iterator &yi, Interval &xi, Fiber &xf);
+ bool crossing_y(Fiber &xf, std::vector::iterator &xi, Interval &yi, Fiber &yf);
+ std::vector::iterator find_interval_crossing_x(Fiber &xf, Fiber &yf);
+ std::vector::iterator find_interval_crossing_y(Fiber &xf, Fiber &yf);
+ Vertex add_cl_vertex(const Point &position, Interval &ival, double ipos);
+ bool add_vertex(Fiber &xf, Fiber &yf, std::vector::iterator xi, std::vector::iterator yi,
+ enum VertexType type);
+ void add_all_edges();
+ std::pair find_neighbor_vertices(VertexPair v_pair, Interval &ival, bool above_equality);
};
-} // end weave namespace
+} // namespace weave
-} // end ocl namespace
+} // namespace ocl
#endif
// end file smart_weave.hpp
diff --git a/src/algo/tsp.hpp b/src/algo/tsp.hpp
index 5c1e2b3c..cdc66705 100644
--- a/src/algo/tsp.hpp
+++ b/src/algo/tsp.hpp
@@ -1,36 +1,36 @@
/* $Id$
- *
+ *
* Copyright (c) 2010-2011 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#ifndef TSP_H
#define TSP_H
-#include
-#include
+#include
#include
+#include
#include
-#include
+#include
#include
#include
-#include
#include
+#include
#include
@@ -41,15 +41,12 @@ namespace tsp {
// loosely based on metric tsp example:
// http://www.boost.org/doc/libs/1_46_1/libs/graph/test/metric_tsp_approx.cpp
-//add edges to the graph (for each node connect it to all other nodes)
-template< typename VertexListGraph,
- typename PointContainer,
- typename WeightMap,
- typename VertexIndexMap>
-void connectAllEuclidean(VertexListGraph& g,
- const PointContainer& points, // vector of (x,y) points
- WeightMap wmap, // Property maps passed by value
- const VertexIndexMap vmap) // Property maps passed by value
+// add edges to the graph (for each node connect it to all other nodes)
+template
+void connectAllEuclidean(VertexListGraph &g,
+ const PointContainer &points, // vector of (x,y) points
+ WeightMap wmap, // Property maps passed by value
+ const VertexIndexMap vmap) // Property maps passed by value
{
using namespace boost;
using namespace std;
@@ -61,9 +58,8 @@ void connectAllEuclidean(VertexListGraph& g,
for (VItr src(verts.first); src != verts.second; src++) {
for (VItr dest(src); dest != verts.second; dest++) {
if (dest != src) {
- double weight( sqrt(
- pow(static_cast( points[vmap[*src ]].x - points[vmap[*dest]].x), 2.0) +
- pow(static_cast( points[vmap[*dest]].y - points[vmap[*src ]].y), 2.0)) );
+ double weight(sqrt(pow(static_cast(points[vmap[*src]].x - points[vmap[*dest]].x), 2.0) +
+ pow(static_cast(points[vmap[*dest]].y - points[vmap[*src]].y), 2.0)));
boost::tie(e, inserted) = add_edge(*src, *dest, g);
wmap[e] = weight; // passed by value??
}
@@ -72,43 +68,43 @@ void connectAllEuclidean(VertexListGraph& g,
}
class TSPSolver {
- typedef boost::adjacency_matrix< boost::undirectedS,
- boost::no_property,
- boost::property< boost::edge_weight_t, double,
- boost::property< boost::edge_index_t, long unsigned int> >,
- boost::no_property
- > Graph;
+ typedef boost::adjacency_matrix<
+ boost::undirectedS, boost::no_property,
+ boost::property>,
+ boost::no_property>
+ Graph;
typedef boost::graph_traits::vertex_descriptor Vertex;
typedef boost::graph_traits::edge_descriptor Edge;
typedef boost::property_map::type WeightMap;
- typedef std::vector< boost::simple_point > PointSet; // was std::set
- typedef std::vector< Vertex > Container;
-
-public:
- TSPSolver () {}
+ typedef std::vector> PointSet; // was std::set
+ typedef std::vector Container;
+
+ public:
+ TSPSolver() {}
virtual ~TSPSolver() {
if (g)
delete g;
}
void run() {
- g = new Graph( points.size() );
+ g = new Graph(points.size());
// connect all vertices
- WeightMap weight_map = boost::get( boost::edge_weight, *g);
- connectAllEuclidean( *g, points, weight_map, boost::get( boost::vertex_index, *g) );
+ WeightMap weight_map = boost::get(boost::edge_weight, *g);
+ connectAllEuclidean(*g, points, weight_map, boost::get(boost::vertex_index, *g));
length = 0.0;
// Run the TSP approx, creating the visitor on the fly.
- boost::metric_tsp_approx(*g, boost::make_tsp_tour_len_visitor(*g, std::back_inserter(output), length, weight_map) );
- //length = len;
- //std::cout << "Number of points: " << boost::num_vertices(*g) << std::endl;
- //std::cout << "Number of edges: " << boost::num_edges(*g) << std::endl;
- //std::cout << "Length of tour: " << len << std::endl;
- //std::cout << "vertices in tour: " << output.size() << std::endl;
- //std::cout << "Elapsed: " << t.elapsed() << std::endl;
+ boost::metric_tsp_approx(*g,
+ boost::make_tsp_tour_len_visitor(*g, std::back_inserter(output), length, weight_map));
+ // length = len;
+ // std::cout << "Number of points: " << boost::num_vertices(*g) << std::endl;
+ // std::cout << "Number of edges: " << boost::num_edges(*g) << std::endl;
+ // std::cout << "Length of tour: " << len << std::endl;
+ // std::cout << "vertices in tour: " << output.size() << std::endl;
+ // std::cout << "Elapsed: " << t.elapsed() << std::endl;
}
void addPoint(double x, double y) {
boost::simple_point pnt;
- pnt.x=x;
- pnt.y=y;
+ pnt.x = x;
+ pnt.y = y;
points.push_back(pnt);
}
void reset() {
@@ -118,31 +114,28 @@ class TSPSolver {
delete g;
}
void printOutput() const {
- int n=0;
- BOOST_FOREACH( Vertex v, output ) {
- std::cout << n++ << " : " << v << "\n" ;
+ int n = 0;
+ BOOST_FOREACH (Vertex v, output) {
+ std::cout << n++ << " : " << v << "\n";
}
}
- double getLength() const {
- return length;
- }
+ double getLength() const { return length; }
boost::python::list getOutput() const {
boost::python::list plist;
- BOOST_FOREACH(Vertex v, output) {
- plist.append( v );
+ BOOST_FOREACH (Vertex v, output) {
+ plist.append(v);
}
return plist;
}
-
-protected:
+
+ protected:
Container output;
PointSet points;
- Graph* g;
+ Graph *g;
double length;
};
+} // namespace tsp
-} // end tsp namespace
-
-} // end ocl namespace
+} // namespace ocl
#endif
diff --git a/src/algo/waterline.cpp b/src/algo/waterline.cpp
index c6d0f36a..18f52bb8 100644
--- a/src/algo/waterline.cpp
+++ b/src/algo/waterline.cpp
@@ -1,57 +1,55 @@
/* $Id$
- *
+ *
* Copyright (c) 2010-2011 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
-#include
+#include
#ifdef _OPENMP
- #include
+#include
#endif
+#include "batchpushcutter.hpp"
#include "millingcutter.hpp"
#include "point.hpp"
#include "triangle.hpp"
#include "waterline.hpp"
-#include "batchpushcutter.hpp"
// #include "weave.hpp"
#include "simple_weave.hpp"
#include "smart_weave.hpp"
-namespace ocl
-{
+namespace ocl {
//******** ********************** */
Waterline::Waterline() {
subOp.clear();
- subOp.push_back( new BatchPushCutter() );
- subOp.push_back( new BatchPushCutter() );
+ subOp.push_back(new BatchPushCutter());
+ subOp.push_back(new BatchPushCutter());
subOp[0]->setXDirection();
subOp[1]->setYDirection();
- nthreads=1;
+ nthreads = 1;
#ifdef _OPENMP
nthreads = omp_get_num_procs();
- //omp_set_dynamic(0);
- //omp_set_nested(1);
+ // omp_set_dynamic(0);
+ // omp_set_nested(1);
#endif
-
}
Waterline::~Waterline() {
@@ -61,17 +59,16 @@ Waterline::~Waterline() {
subOp.clear();
}
-
// run the batchpuschutter sub-operations to get x- and y-fibers
// pass the fibers to weave, and process the weave to get waterline-loops
void Waterline::run2() {
init_fibers();
subOp[0]->run(); // these two are independent, so could/should run in parallel
subOp[1]->run();
-
- xfibers = *( subOp[0]->getFibers() );
- yfibers = *( subOp[1]->getFibers() );
-
+
+ xfibers = *(subOp[0]->getFibers());
+ yfibers = *(subOp[1]->getFibers());
+
weave_process2();
}
@@ -79,14 +76,13 @@ void Waterline::run() {
init_fibers();
subOp[0]->run(); // these two are independent, so could/should run in parallel
subOp[1]->run();
-
- xfibers = *( subOp[0]->getFibers() );
- yfibers = *( subOp[1]->getFibers() );
-
+
+ xfibers = *(subOp[0]->getFibers());
+ yfibers = *(subOp[1]->getFibers());
+
weave_process();
}
-
void Waterline::reset() {
xfibers.clear();
yfibers.clear();
@@ -97,85 +93,85 @@ void Waterline::reset() {
void Waterline::weave_process() {
// std::cout << "Weave...\n" << std::flush;
weave::SimpleWeave weave;
- BOOST_FOREACH( Fiber f, xfibers ) {
+ BOOST_FOREACH (Fiber f, xfibers) {
weave.addFiber(f);
}
- BOOST_FOREACH( Fiber f, yfibers ) {
+ BOOST_FOREACH (Fiber f, yfibers) {
weave.addFiber(f);
}
-
- //std::cout << "Weave::build()..." << std::flush;
- weave.build();
+
+ // std::cout << "Weave::build()..." << std::flush;
+ weave.build();
// std::cout << "done.\n";
-
+
// std::cout << "Weave::face traverse()...";
weave.face_traverse();
// std::cout << "done.\n";
// std::cout << "Weave::get_loops()...";
loops = weave.getLoops();
- // std::cout << "done.\n";
+ // std::cout << "done.\n";
}
void Waterline::weave_process2() {
// std::cout << "Weave...\n" << std::flush;
weave::SmartWeave weave;
- BOOST_FOREACH( Fiber f, xfibers ) {
+ BOOST_FOREACH (Fiber f, xfibers) {
weave.addFiber(f);
}
- BOOST_FOREACH( Fiber f, yfibers ) {
+ BOOST_FOREACH (Fiber f, yfibers) {
weave.addFiber(f);
}
-
- //std::cout << "Weave::build2()..." << std::flush;
- weave.build();
+
+ // std::cout << "Weave::build2()..." << std::flush;
+ weave.build();
// std::cout << "done.\n";
-
+
// std::cout << "Weave::face traverse()...";
weave.face_traverse();
// std::cout << "done.\n";
// std::cout << "Weave::get_loops()...";
loops = weave.getLoops();
- // std::cout << "done.\n";
+ // std::cout << "done.\n";
}
void Waterline::init_fibers() {
// std::cout << " Waterline::init_fibers()\n";
- double minx = surf->bb.minpt.x - 2*cutter->getRadius();
- double maxx = surf->bb.maxpt.x + 2*cutter->getRadius();
- double miny = surf->bb.minpt.y - 2*cutter->getRadius();
- double maxy = surf->bb.maxpt.y + 2*cutter->getRadius();
- int Nx = (int)( (maxx-minx)/sampling );
- int Ny = (int)( (maxy-miny)/sampling );
- std::vector xvals = generate_range(minx,maxx,Nx);
- std::vector yvals = generate_range(miny,maxy,Ny);
- BOOST_FOREACH( double y, yvals ) {
- Point p1 = Point( minx, y, zh );
- Point p2 = Point( maxx, y, zh );
- Fiber f = Fiber( p1 , p2 );
- subOp[0]->appendFiber( f );
+ double minx = surf->bb.minpt.x - 2 * cutter->getRadius();
+ double maxx = surf->bb.maxpt.x + 2 * cutter->getRadius();
+ double miny = surf->bb.minpt.y - 2 * cutter->getRadius();
+ double maxy = surf->bb.maxpt.y + 2 * cutter->getRadius();
+ int Nx = (int)((maxx - minx) / sampling);
+ int Ny = (int)((maxy - miny) / sampling);
+ std::vector xvals = generate_range(minx, maxx, Nx);
+ std::vector yvals = generate_range(miny, maxy, Ny);
+ BOOST_FOREACH (double y, yvals) {
+ Point p1 = Point(minx, y, zh);
+ Point p2 = Point(maxx, y, zh);
+ Fiber f = Fiber(p1, p2);
+ subOp[0]->appendFiber(f);
}
- BOOST_FOREACH( double x, xvals ) {
- Point p1 = Point( x, miny, zh );
- Point p2 = Point( x, maxy, zh );
- Fiber f = Fiber( p1 , p2 );
- subOp[1]->appendFiber( f );
+ BOOST_FOREACH (double x, xvals) {
+ Point p1 = Point(x, miny, zh);
+ Point p2 = Point(x, maxy, zh);
+ Fiber f = Fiber(p1, p2);
+ subOp[1]->appendFiber(f);
}
}
// return a double-vector [ start , ... , end ] with N elements
// for generating fibers.
-std::vector Waterline::generate_range( double start, double end, int N) const {
+std::vector Waterline::generate_range(double start, double end, int N) const {
std::vector output;
- double d = (end-start)/ (double)N;
+ double d = (end - start) / (double)N;
double v = start;
- for (int n=0; n< (N+1); ++n) {
- output.push_back( v );
- v=v+d;
+ for (int n = 0; n < (N + 1); ++n) {
+ output.push_back(v);
+ v = v + d;
}
return output;
}
-}// end namespace
+} // namespace ocl
// end file waterline.cpp
diff --git a/src/algo/waterline.hpp b/src/algo/waterline.hpp
index 912260b7..bd80d4a1 100644
--- a/src/algo/waterline.hpp
+++ b/src/algo/waterline.hpp
@@ -1,23 +1,23 @@
/* $Id$
- *
+ *
* Copyright (c) 2010-2011 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#ifndef WATERLINE_H
#define WATERLINE_H
@@ -26,15 +26,12 @@
#include
#include
-#include "point.hpp"
-#include "fiber.hpp"
#include "batchpushcutter.hpp"
+#include "fiber.hpp"
#include "operation.hpp"
+#include "point.hpp"
-
-namespace ocl
-{
-
+namespace ocl {
/// \brief a Waterline toolpath follows the shape of the model at a constant z-height in the xy-plane
@@ -42,51 +39,44 @@ namespace ocl
/// from an STL-model. Waterline uses two BatchPushCutter sub-operations to find out where the CL-points are located
/// and a Weave to split and order the CL-points correctly into loops.
class Waterline : public Operation {
- public:
- /// create an empty Waterline object
- Waterline();
- virtual ~Waterline();
-
- /// Set the z-coordinate for the waterline we generate
- void setZ(const double z) {
- zh = z;
- }
- /// run the Waterline algorithm. setSTL, setCutter, setSampling, and setZ must
- /// be called before a call to run()
- virtual void run();
- virtual void run2();
-
- /// returns a vector< vector< Point > > with the resulting waterline loops
- std::vector< std::vector > getLoops() const {
- return loops;
- }
- void reset();
-
- protected:
- /// from xfibers and yfibers, build the weave, run face-traverse, and write toolpaths to loops
- void weave_process();
- void weave_process2();
-
- /// initialization of fibers
- void init_fibers();
- /// x and y-coordinates for fiber generation
- std::vector generate_range( double start, double end, int N) const;
-
- // DATA
- /// the z-height for this Waterline
- double zh;
- /// the results of this operation, a list of loops
- std::vector< std::vector > loops;
-
- /// x-fibers for this operation
- std::vector xfibers;
- /// y-fibers for this operation
- std::vector yfibers;
-
-};
+ public:
+ /// create an empty Waterline object
+ Waterline();
+ virtual ~Waterline();
+
+ /// Set the z-coordinate for the waterline we generate
+ void setZ(const double z) { zh = z; }
+ /// run the Waterline algorithm. setSTL, setCutter, setSampling, and setZ must
+ /// be called before a call to run()
+ virtual void run();
+ virtual void run2();
+
+ /// returns a vector< vector< Point > > with the resulting waterline loops
+ std::vector> getLoops() const { return loops; }
+ void reset();
+
+ protected:
+ /// from xfibers and yfibers, build the weave, run face-traverse, and write toolpaths to loops
+ void weave_process();
+ void weave_process2();
+ /// initialization of fibers
+ void init_fibers();
+ /// x and y-coordinates for fiber generation
+ std::vector generate_range(double start, double end, int N) const;
+ // DATA
+ /// the z-height for this Waterline
+ double zh;
+ /// the results of this operation, a list of loops
+ std::vector> loops;
+
+ /// x-fibers for this operation
+ std::vector xfibers;
+ /// y-fibers for this operation
+ std::vector yfibers;
+};
-} // end namespace
+} // namespace ocl
#endif
diff --git a/src/algo/weave.cpp b/src/algo/weave.cpp
index ab41c8a5..650a0d45 100644
--- a/src/algo/weave.cpp
+++ b/src/algo/weave.cpp
@@ -1,23 +1,23 @@
/* $Id$
- *
+ *
* Copyright (c) 2010-2011 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#include
#include
@@ -25,19 +25,16 @@
#include "weave.hpp"
+namespace ocl {
-namespace ocl
-{
-
-namespace weave
-{
+namespace weave {
int VertexProps::count = 0;
-void Weave::addFiber(Fiber& f) {
- if ( f.dir.xParallel() && !f.empty() ) {
+void Weave::addFiber(Fiber &f) {
+ if (f.dir.xParallel() && !f.empty()) {
xfibers.push_back(f);
- } else if ( f.dir.yParallel() && !f.empty() ) {
+ } else if (f.dir.yParallel() && !f.empty()) {
yfibers.push_back(f);
} else if (!f.empty()) {
assert(0); // fiber must be either x or y
@@ -46,78 +43,75 @@ void Weave::addFiber(Fiber& f) {
// traverse the graph putting loops of vertices into the loops variable
// this figure illustrates next-pointers: http://www.anderswallin.net/wp-content/uploads/2011/05/weave2_zoom.png
-void Weave::face_traverse() {
+void Weave::face_traverse() {
// std::cout << " traversing graph with " << clVertexSet.size() << " cl-points\n";
- while ( !clVertexSet.empty() ) { // while unprocessed cl-vertices remain
- std::vector loop; // start on a new loop
+ while (!clVertexSet.empty()) { // while unprocessed cl-vertices remain
+ std::vector loop; // start on a new loop
Vertex current = *(clVertexSet.begin());
Vertex first = current;
-
- do { // traverse around the loop
- assert( g[current].type == CL ); // we only want cl-points in the loop
+
+ do { // traverse around the loop
+ assert(g[current].type == CL); // we only want cl-points in the loop
loop.push_back(current);
- clVertexSet.erase(current); // remove from set of unprocesser cl-verts
- std::vector outEdges = g.out_edges(current); // find the edge to follow
- //if (outEdges.size() != 1 )
- // std::cout << " outEdges.size() = " << outEdges.size() << "\n";
- assert( outEdges.size() == 1 ); // cl-points are always at ends of intervals, so they have only one out-edge
- Edge currentEdge = outEdges[0];
- do { // following next, find a CL point
- current = g.target(currentEdge);
+ clVertexSet.erase(current); // remove from set of unprocesser cl-verts
+ std::vector outEdges = g.out_edges(current); // find the edge to follow
+ // if (outEdges.size() != 1 )
+ // std::cout << " outEdges.size() = " << outEdges.size() << "\n";
+ assert(outEdges.size() == 1); // cl-points are always at ends of intervals, so they have only one out-edge
+ Edge currentEdge = outEdges[0];
+ do { // following next, find a CL point
+ current = g.target(currentEdge);
currentEdge = g[currentEdge].next;
- } while ( g[current].type != CL );
- } while (current!=first); // end the loop when we arrive at the start
-
+ } while (g[current].type != CL);
+ } while (current != first); // end the loop when we arrive at the start
+
loops.push_back(loop); // add the processed loop to the master list of all loops
}
}
-
-std::vector< std::vector > Weave::getLoops() const {
- std::vector< std::vector > loop_list;
- BOOST_FOREACH( std::vector loop, loops ) {
+std::vector> Weave::getLoops() const {
+ std::vector> loop_list;
+ BOOST_FOREACH (std::vector loop, loops) {
std::vector point_list;
- BOOST_FOREACH( Vertex v, loop ) {
- point_list.push_back( g[v].position );
+ BOOST_FOREACH (Vertex v, loop) {
+ point_list.push_back(g[v].position);
}
loop_list.push_back(point_list);
}
return loop_list;
}
-
// this can cause a build error when both face and vertex descriptors have the same type
// i.e. unsigned int (?)
// operator[] below "g[*itr].type" then looks for FaceProps.type which does not exist...
-void Weave::printGraph() {
- std::cout << " number of vertices: " << g.num_vertices() << "\n";
- std::cout << " number of edges: " << g.num_edges() << "\n";
+void Weave::printGraph() {
+ std::cout << " number of vertices: " << g.num_vertices() << "\n";
+ std::cout << " number of edges: " << g.num_edges() << "\n";
- int n=0, n_cl=0, n_internal=0;
- BOOST_FOREACH(Vertex v, g.vertices() ) {
- if ( g[v].type == CL )
+ int n = 0, n_cl = 0, n_internal = 0;
+ BOOST_FOREACH (Vertex v, g.vertices()) {
+ if (g[v].type == CL)
++n_cl;
else
++n_internal;
++n;
}
-
+
std::cout << " counted " << n << " vertices\n";
std::cout << " CL-nodes: " << n_cl << "\n";
std::cout << " internal-nodes: " << n_internal << "\n";
}
-
+
// string representation
-std::string Weave::str() {
+std::string Weave::str() {
std::ostringstream o;
o << "Weave2\n";
o << " " << xfibers.size() << " X-fibers\n";
o << " " << yfibers.size() << " Y-fibers\n";
return o.str();
}
-
-} // end weave namespace
+} // namespace weave
-} // end ocl namespace
+} // namespace ocl
// end file weave.cpp
diff --git a/src/algo/weave.hpp b/src/algo/weave.hpp
index acf4c740..2e2583b2 100644
--- a/src/algo/weave.hpp
+++ b/src/algo/weave.hpp
@@ -1,32 +1,31 @@
/* $Id$
- *
+ *
* Copyright (c) 2010-2011 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#ifndef WEAVE_HPP
#define WEAVE_HPP
#include
-
#include "fiber.hpp"
-#include "weave_typedef.hpp"
#include "halfedgediagram.hpp"
+#include "weave_typedef.hpp"
namespace ocl {
@@ -34,33 +33,33 @@ namespace weave {
// Abstract base-class for weave-implementations. build() must be implemented in sub-class!
class Weave {
- public:
- Weave() {}
- virtual ~Weave() {}
- /// add Fiber f to the graph
- /// each fiber should be either in the X or Y-direction
- /// FIXME: separate addXFiber and addYFiber methods?
- void addFiber(Fiber& f);
- /// from the list of fibers, build a graph
- virtual void build() = 0;
- /// run planar_face_traversal to get the waterline loops
- void face_traverse();
- /// return list of loops
- std::vector< std::vector > getLoops() const;
- /// string representation
- std::string str() ;
- void printGraph() ;
-
- protected:
- WeaveGraph g; ///< the weave-graph
- std::vector< std::vector > loops; ///< output: list of loops in this weave
- std::vector xfibers; ///< the X-fibers
- std::vector yfibers; ///< the Y-fibers
- std::set clVertexSet; ///< set of CL-points
+ public:
+ Weave() {}
+ virtual ~Weave() {}
+ /// add Fiber f to the graph
+ /// each fiber should be either in the X or Y-direction
+ /// FIXME: separate addXFiber and addYFiber methods?
+ void addFiber(Fiber &f);
+ /// from the list of fibers, build a graph
+ virtual void build() = 0;
+ /// run planar_face_traversal to get the waterline loops
+ void face_traverse();
+ /// return list of loops
+ std::vector> getLoops() const;
+ /// string representation
+ std::string str();
+ void printGraph();
+
+ protected:
+ WeaveGraph g; ///< the weave-graph
+ std::vector> loops; ///< output: list of loops in this weave
+ std::vector xfibers; ///< the X-fibers
+ std::vector yfibers; ///< the Y-fibers
+ std::set clVertexSet; ///< set of CL-points
};
-} // end weave namespace
+} // namespace weave
-} // end ocl namespace
+} // namespace ocl
#endif
// end file weave.hpp
diff --git a/src/algo/weave_typedef.hpp b/src/algo/weave_typedef.hpp
index 93ae3c70..b59cb899 100644
--- a/src/algo/weave_typedef.hpp
+++ b/src/algo/weave_typedef.hpp
@@ -1,23 +1,23 @@
/* $Id$
- *
+ *
* Copyright (c) 2010-2011 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#ifndef WEAVE_TYPEDEF_H
#define WEAVE_TYPEDEF_H
@@ -28,53 +28,47 @@ namespace ocl {
namespace weave {
-
// we use the traits-class here so that EdgeProps can have Edge as a member
-typedef boost::adjacency_list_traits::edge_descriptor Edge;
+typedef boost::adjacency_list_traits::edge_descriptor
+ Edge;
/// vertex type: CL-point, internal point, adjacent point
-enum VertexType {CL, CL_DONE, ADJ, TWOADJ, INT, FULLINT};
+enum VertexType { CL, CL_DONE, ADJ, TWOADJ, INT, FULLINT };
/// vertex properties
struct VertexProps {
- VertexProps() {
- init();
- }
+ VertexProps() { init(); }
/// construct vertex at position p with type t
- VertexProps( Point p, VertexType t) {
- position=p;
- type=t;
+ VertexProps(Point p, VertexType t) {
+ position = p;
+ type = t;
init();
}
/// construct vertex at position p with type t
- VertexProps( Point p, VertexType t, std::vector::iterator x, std::vector::iterator y )
- : xi( x ), yi( y ) {
- position=p;
- type=t;
+ VertexProps(Point p, VertexType t, std::vector::iterator x, std::vector::iterator y)
+ : xi(x), yi(y) {
+ position = p;
+ type = t;
init();
}
-
+
void init() {
index = count;
count++;
}
VertexType type;
-// HE data
+ // HE data
/// the position of the vertex
Point position;
/// index of vertex
int index;
/// global vertex count
static int count;
-
+
// x interval
std::vector::iterator xi;
// y interval
std::vector::iterator yi;
-
};
/// edge properties
@@ -82,68 +76,64 @@ struct EdgeProps {
EdgeProps() {}
/// the next edge, counterclockwise, from this edge
Edge next;
- /// previous edge, to make Weave::build() faster, since we avoid calling hedi::previous_edge()
+ /// previous edge, to make Weave::build() faster, since we avoid calling hedi::previous_edge()
Edge prev;
/// the twin edge
Edge twin;
};
-typedef unsigned int Face;
+typedef unsigned int Face;
/// properties of a face in the weave
struct FaceProps {
/// create face with given edge, generator, and type
- FaceProps( Edge e ) {
- edge = e;
- }
+ FaceProps(Edge e) { edge = e; }
/// face index
Face idx;
/// one edge that bounds this face
Edge edge;
};
-
-
// the graph type for the weave
-typedef ocl::hedi::HEDIGraph< boost::listS, // out-edges stored here
- boost::listS, // vertex set stored here
- boost::bidirectionalS, // undirecgted or bidirectional graph?
- VertexProps, // vertex properties
- EdgeProps, // edge properties
- FaceProps, // face properties
- boost::no_property, // graph properties
- boost::listS // edge storage
- > WeaveGraph;
+typedef ocl::hedi::HEDIGraph
+ WeaveGraph;
typedef WeaveGraph::Vertex Vertex;
-typedef WeaveGraph::VertexItr VertexItr;
+typedef WeaveGraph::VertexItr VertexItr;
-//typedef boost::graph_traits< WeaveGraph >::vertex_descriptor Vertex;
+// typedef boost::graph_traits< WeaveGraph >::vertex_descriptor Vertex;
//
-// typedef boost::graph_traits< WeaveGraph >::edge_descriptor Edge;
-//typedef boost::graph_traits< WeaveGraph >::edge_iterator EdgeItr;
-//typedef boost::graph_traits< WeaveGraph >::out_edge_iterator OutEdgeItr;
-//typedef boost::graph_traits< WeaveGraph >::adjacency_iterator AdjacencyItr;
+// typedef boost::graph_traits< WeaveGraph >::edge_descriptor Edge;
+// typedef boost::graph_traits< WeaveGraph >::edge_iterator EdgeItr;
+// typedef boost::graph_traits< WeaveGraph >::out_edge_iterator OutEdgeItr;
+// typedef boost::graph_traits< WeaveGraph >::adjacency_iterator AdjacencyItr;
/// intersections between intervals are stored as a VertexPair
/// pair.first is a vertex descriptor of the weave graph
/// pair.second is the coordinate along the fiber of the intersection
-typedef std::pair< Vertex, double > VertexPair;
+typedef std::pair VertexPair;
/// compare based on pair.second, the coordinate of the intersection
struct VertexPairCompare {
/// comparison operator
- bool operator() (const VertexPair& lhs, const VertexPair& rhs) const
- { return lhs.second < rhs.second ;}
+ bool operator()(const VertexPair &lhs, const VertexPair &rhs) const { return lhs.second < rhs.second; }
};
/// intersections stored in this set (for rapid finding of neighbors etc)
-typedef std::set< VertexPair, VertexPairCompare > VertexIntersectionSet;
+typedef std::set VertexIntersectionSet;
-typedef VertexIntersectionSet::iterator VertexPairIterator;
+typedef VertexIntersectionSet::iterator VertexPairIterator;
-} // end weave namespace
+} // namespace weave
-} // end ocl namespace
+} // namespace ocl
#endif
// end file weave_typedef.hpp
diff --git a/src/algo/zigzag.hpp b/src/algo/zigzag.hpp
index 1b59fa7f..4fdb0957 100644
--- a/src/algo/zigzag.hpp
+++ b/src/algo/zigzag.hpp
@@ -1,104 +1,97 @@
/* $Id$
- *
+ *
* Copyright (c) 2010 Anders Wallin (anders.e.e.wallin "at" gmail.com).
- *
- * This file is part of OpenCAMlib
+ *
+ * This file is part of OpenCAMlib
* (see https://github.com/aewallin/opencamlib).
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
-*/
+ */
#ifndef ZIGZAG_H
#define ZIGZAG_H
+#include
#include
#include