Skip to content

Commit

Permalink
added arc line path pathfinish files for work on Issue 3: Path Input,…
Browse files Browse the repository at this point in the history
… Path Output
  • Loading branch information
danheeks committed Mar 22, 2010
1 parent 3566936 commit 5cbe842
Show file tree
Hide file tree
Showing 16 changed files with 815 additions and 108 deletions.
76 changes: 76 additions & 0 deletions OpenCamLib/OpenCamLib.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\arc.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\ballcutter.cpp"
>
Expand All @@ -187,6 +199,18 @@
/>
</FileConfiguration>
</File>
<File
RelativePath="..\bullcutter.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\cutter.cpp"
>
Expand Down Expand Up @@ -245,6 +269,18 @@
/>
</FileConfiguration>
</File>
<File
RelativePath="..\line.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\numeric.cpp"
>
Expand Down Expand Up @@ -273,6 +309,30 @@
RelativePath=".\OpenCamLib.cpp"
>
</File>
<File
RelativePath="..\path.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\pathfinish.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\pfinish.cpp"
>
Expand Down Expand Up @@ -347,6 +407,10 @@
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath="..\arc.h"
>
</File>
<File
RelativePath="..\cutter.h"
>
Expand All @@ -355,6 +419,10 @@
RelativePath="..\kdtree.h"
>
</File>
<File
RelativePath="..\line.h"
>
</File>
<File
RelativePath="..\numeric.h"
>
Expand All @@ -363,6 +431,14 @@
RelativePath="..\ocl.h"
>
</File>
<File
RelativePath="..\path.h"
>
</File>
<File
RelativePath="..\pathfinish.h"
>
</File>
<File
RelativePath="..\pfinish.h"
>
Expand Down
87 changes: 87 additions & 0 deletions arc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* Copyright 2010 Anders Wallin (anders.e.e.wallin "at" gmail.com)
*
* This file is part of OpenCAMlib.
*
* OpenCAMlib is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenCAMlib 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenCAMlib. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include "arc.h"

Arc::Arc(const Point &p1in, const Point &p2in, const Point &cin, bool dirin) {
p1=p1in;
p2=p2in;
c=cin;
dir=dirin;
setProperties();
}

Arc::Arc(const Arc &a) {
p1=a.p1;
p2=a.p2;
c=a.c;
dir=a.dir;
setProperties();
}

void Arc::setProperties() {
// arc properties
Point vs = Point(c, p1).xyPerp();
Point ve = Point(c, p2).xyPerp();

if(!dir) {
vs = -vs; // reverse directions for CW arc
ve = -ve;
}

radius = vs.xyNorm();
length = fabs(xyIncludedAngle(vs, ve, dir)) * radius;
}

std::ostream& operator<<(std::ostream &stream, const Arc& a)
{
stream << "(" << a.p1 << ", " << a.p2 << ", " << a.c << ", " << a.dir << ")";
return stream;
}

Point Arc::getPoint(double param)const {
/// returns a point which is 0-1 along span
if(fabs(param) < 0.00000000000001)return p1;
if(fabs(param - 1.0) < 0.00000000000001)return p2;

double d = param * length;
if(!dir)d = -d;
Point v(c, p1);
v.xyRotate(d * dir / radius);
return v + c;
}

double Arc::xyIncludedAngle(const Point& v1, const Point& v2, bool dir) {
// returns the absolute included angle between 2 vectors in the direction of dir ( true=acw false=cw)
int d = dir ? 1 : (-1);
double inc_ang = v1.dot(v2);
if(inc_ang > 1. - 1.0e-10) return 0;
if(inc_ang < -1. + 1.0e-10)
inc_ang = 3.1415926535897932;
else { // dot product, v1 . v2 = cos ang
if(inc_ang > 1.0) inc_ang = 1.0;
inc_ang = acos(inc_ang); // 0 to pi radians

double x = v1.x * v2.x + v1.y * v2.y;
if(d * x < 0) inc_ang = 2 * 3.1415926535897932 - inc_ang ; // cp
}
return d * inc_ang;
}
58 changes: 58 additions & 0 deletions arc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* Copyright 2010 Anders Wallin (anders.e.e.wallin "at" gmail.com)
*
* This file is part of OpenCAMlib.
*
* OpenCAMlib is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenCAMlib 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenCAMlib. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARC_H
#define ARC_H

#include <iostream>
#include "point.h"

///
/// \brief a finite line in 3D space specified by its end points (p1, p2)
///

///
/// longer documentation here.
///
class Arc {
double length; // 2d length
double radius;

public:
Arc(){}
Arc(const Point &p1, const Point &p2, const Point &c, bool dir);
Arc(const Arc &a);

// text output
friend std::ostream& operator<<(std::ostream &stream, const Arc &a);

/// start point
Point p1;
/// end point
Point p2;
/// centre point
Point c;
/// direction true for anti-clockwise
bool dir;

double length2d()const{return length;}
Point getPoint(double fraction)const;
void setProperties();
double xyIncludedAngle(const Point& v1, const Point& v2, bool dir = true);
};

#endif
4 changes: 2 additions & 2 deletions kdtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@


KDNode::KDNode(int d, double cv, KDNode *hi_c, KDNode *lo_c,
std::list<Triangle> *tlist, int lev)
const std::list<Triangle> *tlist, int lev)
{
dim = d;
cutval = cv;
Expand All @@ -56,7 +56,7 @@ KDNode::KDNode(int d, double cv, KDNode *hi_c, KDNode *lo_c,

int KDTree::level = 0;
/// given a list of triangles, build and return the root node of a kd-tree with the triangles
KDNode* KDTree::build_kdtree(std::list<Triangle> *tris, unsigned int bucketSize)
KDNode* KDTree::build_kdtree(const std::list<Triangle> *tris, unsigned int bucketSize)
{

if (tris->size() == 0) {
Expand Down
6 changes: 3 additions & 3 deletions kdtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class KDNode {
/// lev is an experimental parameter (supposed to be the level of the node, but not working currently...)
KDNode(int d, double cv, KDNode *hi_c,
KDNode *lo_c,
std::list<Triangle> *tlist,
const std::list<Triangle> *tlist,
int lev);
std::string str();
friend std::ostream &operator<<(std::ostream &stream, const KDNode node);
Expand All @@ -68,7 +68,7 @@ class KDNode {
/// Child-node lo.
KDNode *lo;
/// A list of triangles, if this is a bucket-node
std::list<Triangle> *tris;
const std::list<Triangle> *tris;
};

///
Expand All @@ -80,7 +80,7 @@ class KDNode {
class KDTree {
public:
/// build a kd-tree from a list of triangles. return root of tree.
static KDNode* build_kdtree(std::list<Triangle> *tris, unsigned int bucketSize);
static KDNode* build_kdtree(const std::list<Triangle> *tris, unsigned int bucketSize);
/// calculate along which dimension kd-tree should cut
static Spread* spread(const std::list<Triangle> *tris);
/// search KDTree for triangles under the cutter positioned at cl
Expand Down
50 changes: 50 additions & 0 deletions line.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Copyright 2010 Anders Wallin (anders.e.e.wallin "at" gmail.com)
*
* This file is part of OpenCAMlib.
*
* OpenCAMlib is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenCAMlib 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenCAMlib. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include "line.h"

Line::Line(const Point &p1in, const Point &p2in)
{
p1=p1in;
p2=p2in;
}

Line::Line(const Line &l)
{
p1=l.p1;
p2=l.p2;
}

std::ostream& operator<<(std::ostream &stream, const Line& l)
{
stream << "(" << l.p1 << ", " << l.p2 << ")";
return stream;
}

double Line::length2d()const
{
return Point(p1, p2).xyNorm();
}

Point Line::getPoint(double param)const
{
return Point(p1, p2) * param + p1;
}

0 comments on commit 5cbe842

Please sign in to comment.