Revision: 65863
http://sourceforge.net/p/brlcad/code/65863
Author: d_rossberg
Date: 2015-08-10 14:01:31 +0000 (Mon, 10 Aug 2015)
Log Message:
-----------
essentially the patches from http://sourceforge.net/p/brlcad/patches/300/ "Pipe
primitive interface and implementation"
may need some additional tests etc.
thanks to Andrei Popescu, Ilinca Andrei, and Kalpit Thakkar for providing the
patches
Modified Paths:
--------------
rt^3/trunk/src/coreInterface/CMakeLists.txt
rt^3/trunk/src/libge/CMakeLists.txt
rt^3/trunk/tests/coreInterface/CMakeLists.txt
rt^3/trunk/tests/coreInterface/halfspace.cpp
rt^3/trunk/tests/coreInterface/primitives.cpp
rt^3/trunk/tests/coreInterface/primitives.h
rt^3/trunk/tests/libge/CMakeLists.txt
Added Paths:
-----------
rt^3/trunk/include/brlcad/Pipe.h
rt^3/trunk/src/coreInterface/Pipe.cpp
rt^3/trunk/tests/coreInterface/cone.cpp
rt^3/trunk/tests/coreInterface/ellipsoid.cpp
rt^3/trunk/tests/coreInterface/pipe.cpp
rt^3/trunk/tests/coreInterface/sphere.cpp
Added: rt^3/trunk/include/brlcad/Pipe.h
===================================================================
--- rt^3/trunk/include/brlcad/Pipe.h (rev 0)
+++ rt^3/trunk/include/brlcad/Pipe.h 2015-08-10 14:01:31 UTC (rev 65863)
@@ -0,0 +1,122 @@
+/* P I P E . H
+ * BRL-CAD
+ *
+ * Copyright (c) 2014 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 file; see the file named COPYING for more
+ * information.
+ */
+/** @file Pipe.h
+ *
+ * BRL-CAD core C++ interface:
+ * pipe (ID_PIPE) database object declaration
+ */
+
+#ifndef BRLCAD_PIPE_INCLUDED
+#define BRLCAD_PIPE_INCLUDED
+
+#include <brlcad/Object.h>
+
+
+struct rt_pipe_internal;
+struct wdb_pipept;
+
+
+namespace BRLCAD {
+ class BRLCAD_COREINTERFACE_EXPORT Pipe : public Object {
+ public:
+ Pipe(void) throw(bad_alloc);
+ Pipe(const Pipe& original) throw(bad_alloc);
+ virtual ~Pipe(void) throw();
+
+ const Pipe& operator=(const Pipe& original) throw(bad_alloc);
+
+ class BRLCAD_COREINTERFACE_EXPORT ControlPoint {
+ public:
+ ControlPoint(void) throw() : m_pipe(0), m_controlPoint(0) {}
+ ControlPoint(const ControlPoint& original) throw() :
m_pipe(original.m_pipe), m_controlPoint(original.m_controlPoint) {}
+ ~ControlPoint(void) throw() {}
+
+ const ControlPoint& operator=(const ControlPoint& original)
throw() {
+ m_pipe = original.m_pipe;
+ m_controlPoint = original.m_controlPoint;
+
+ return *this;
+ }
+
+ operator void*(void) {
+ return m_pipe;
+ }
+
+ Vector3D Point(void) const throw();
+ void SetPoint(const Vector3D& point) throw();
+
+ double InnerDiameter(void) const throw();
+ void SetInnerDiameter(double id) throw();
+
+ double OuterDiameter(void) const throw();
+ void SetOuterDiameter(double od) throw();
+
+ double BendRadius(void) const throw();
+ void SetBendRadius(double br) throw();
+
+ private:
+ rt_pipe_internal* m_pipe;
+ wdb_pipept* m_controlPoint;
+
+ ControlPoint(rt_pipe_internal* pipe,
+ wdb_pipept* controlPoint) throw() :
m_pipe(pipe), m_controlPoint(controlPoint) {}
+
+ friend class Pipe;
+ };
+
+ ControlPoint Get(size_t index) throw();
+ ControlPoint AppendControlPoint(const Vector3D& point,
+ double innerDiameter,
+ double outerDiameter,
+ double bendRadius)
throw(bad_alloc);
+ ControlPoint InsertControlPoint(size_t index,
+ const Vector3D& point,
+ double innerDiameter,
+ double outerDiameter,
+ double bendRadius)
throw(bad_alloc);
+ void DeleteControlPoint(size_t index) throw();
+
+ // inherited from BRLCAD::Object
+ virtual const Object& operator=(const Object& original)
throw(bad_alloc);
+ virtual Object* Clone(void) const throw(bad_alloc,
std::bad_alloc);
+ static const char* ClassName(void) throw();
+ virtual const char* Type(void) const throw();
+ virtual bool IsValid(void) const throw();
+
+ protected:
+ Pipe(resource* resp,
+ directory* pDir,
+ rt_db_internal* ip,
+ db_i* dbip = 0) throw();
+
+ friend class ConstDatabase;
+
+ private:
+ rt_pipe_internal* m_internalp;
+
+ const rt_pipe_internal* Internal(void) const throw();
+ rt_pipe_internal* Internal(void) throw();
+
+ friend class Database;
+ };
+};
+
+
+#endif // BRLCAD_PIPE_INCLUDED
Property changes on: rt^3/trunk/include/brlcad/Pipe.h
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: rt^3/trunk/src/coreInterface/CMakeLists.txt
===================================================================
--- rt^3/trunk/src/coreInterface/CMakeLists.txt 2015-08-09 22:29:30 UTC (rev
65862)
+++ rt^3/trunk/src/coreInterface/CMakeLists.txt 2015-08-10 14:01:31 UTC (rev
65863)
@@ -68,6 +68,7 @@
ParabolicCylinder.cpp
Paraboloid.cpp
Particle.cpp
+ Pipe.cpp
Sketch.cpp
Sphere.cpp
Torus.cpp
Added: rt^3/trunk/src/coreInterface/Pipe.cpp
===================================================================
--- rt^3/trunk/src/coreInterface/Pipe.cpp (rev 0)
+++ rt^3/trunk/src/coreInterface/Pipe.cpp 2015-08-10 14:01:31 UTC (rev
65863)
@@ -0,0 +1,448 @@
+/* P I P E . C P P
+ * BRL-CAD
+ *
+ * Copyright (c) 2014 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 file; see the file named COPYING for more
+ * information.
+ */
+/** @file Pipe.cpp
+ *
+ * BRL-CAD core C++ interface:
+ * pipe (ID_PIPE) database object implementation
+ */
+
+#include <cstring>
+#include <cassert>
+
+#include "raytrace.h"
+#include "rt/geom.h"
+#include "bu/parallel.h"
+
+#include <brlcad/Pipe.h>
+
+
+using namespace BRLCAD;
+
+
+static void PipeCopy
+(
+ rt_pipe_internal* copiedPipe,
+ const rt_pipe_internal* originalPipe
+) {
+ RT_PIPE_CK_MAGIC(copiedPipe);
+ RT_PIPE_CK_MAGIC(originalPipe);
+
+ /* Initialize the new pipe internal structure */
+ bu_list_free(&copiedPipe->pipe_segs_head);
+ copiedPipe->pipe_count = originalPipe->pipe_count;
+
+ if (originalPipe->pipe_count > 0) {
+ /* We use two pointers here : One traverses the pipe internal
+ * to be copied and one traverses the pipe internal where it
+ * is being copied.
+ */
+ wdb_pipept* temp = BU_LIST_FIRST(wdb_pipept,
&(originalPipe->pipe_segs_head));
+ wdb_pipept* itr = BU_LIST_FIRST(wdb_pipept,
&(copiedPipe->pipe_segs_head));
+
+ /* Allocate memory for every new entry in the bu_list of the
+ * new pipe internal and copy the contents of pipe internal to
+ * be copied into it. We use a separate structure for that
+ * and that push that structure into the list. ------> (1)
+ */
+ wdb_pipept* ctlPoint;
+ BU_GET(ctlPoint, wdb_pipept);
+
+ for(int i = 0; i < 3; i++)
+ ctlPoint->pp_coord[i] = temp->pp_coord[i];
+
+ ctlPoint->pp_id = temp->pp_id;
+ ctlPoint->pp_od = temp->pp_od;
+ ctlPoint->pp_bendradius = temp->pp_bendradius;
+
+ BU_LIST_PUSH(&itr->l, &ctlPoint->l);
+
+ /* Perform the task done in (1) iteratively till the complete
+ * list has been formed.
+ */
+ for (int count = 1; count < copiedPipe->pipe_count; ++count) {
+ itr = BU_LIST_NEXT(wdb_pipept, &itr->l);
+ temp = BU_LIST_NEXT(wdb_pipept, &temp->l);
+ BU_GET(ctlPoint, wdb_pipept);
+
+ for(int i = 0; i < 3; i++)
+ ctlPoint->pp_coord[i] = temp->pp_coord[i];
+
+ ctlPoint->pp_id = temp->pp_id;
+ ctlPoint->pp_od = temp->pp_od;
+ ctlPoint->pp_bendradius = temp->pp_bendradius;
+
+ BU_LIST_PUSH(&itr->l, &ctlPoint->l);
+ }
+ }
+}
+
+
+Pipe::Pipe(void) throw(bad_alloc) : Object() {
+ if (!BU_SETJUMP) {
+ BU_GET(m_internalp, rt_pipe_internal);
+ m_internalp->pipe_magic = RT_PIPE_INTERNAL_MAGIC;
+ m_internalp->pipe_count = 0;
+ BU_LIST_INIT(&(m_internalp->pipe_segs_head));
+ }
+ else {
+ BU_UNSETJUMP;
+ throw bad_alloc("BRLCAD::Pipe::Pipe");
+ }
+
+ BU_UNSETJUMP;
+}
+
+
+Pipe::Pipe
+(
+ const Pipe& original
+) throw(bad_alloc) {
+ if (!BU_SETJUMP) {
+ BU_GET(m_internalp, rt_pipe_internal);
+ m_internalp->pipe_magic = RT_PIPE_INTERNAL_MAGIC;
+ m_internalp->pipe_count = 0;
+ BU_LIST_INIT(&(m_internalp->pipe_segs_head));
+ PipeCopy(m_internalp, original.Internal());
+ }
+ else {
+ BU_UNSETJUMP;
+ throw bad_alloc("BRLCAD::Pipe::Pipe");
+ }
+
+ BU_UNSETJUMP;
+}
+
+
+Pipe::~Pipe
+(
+ void
+) throw() {
+ if (m_internalp != 0) {
+ bu_list_free(&m_internalp->pipe_segs_head);
+ bu_free(m_internalp, "BRLCAD::Pipe::~Pipe::m_internalp");
+ }
+}
+
+
+const Pipe& Pipe::operator=
+(
+ const Pipe& original
+) throw(bad_alloc) {
+ if(&original != this) {
+ Copy(original);
+
+ if(!BU_SETJUMP)
+ PipeCopy(Internal(), original.Internal());
+ else {
+ BU_UNSETJUMP;
+ throw bad_alloc("BRLAD::Pipe::operator=");
+ }
+
+ BU_UNSETJUMP;
+ }
+
+ return *this;
+}
+
+
+Vector3D Pipe::ControlPoint::Point(void) const throw() {
+ assert(m_pipe != 0);
+
+ Vector3D ret;
+
+ if(m_pipe != 0)
+ ret = Vector3D(m_controlPoint->pp_coord);
+
+ return ret;
+}
+
+
+void Pipe::ControlPoint::SetPoint
+(
+ const Vector3D& point
+) throw() {
+ assert(m_pipe != 0);
+
+ if(m_pipe != 0) {
+ for(int i = 0; i < 3; i++)
+ m_controlPoint->pp_coord[i] = point.coordinates[i];
+ }
+}
+
+
+double Pipe::ControlPoint::InnerDiameter(void) const throw() {
+ assert(m_pipe != 0);
+
+ double ret;
+
+ if(m_pipe != 0)
+ ret = m_controlPoint->pp_id;
+
+ return ret;
+}
+
+
+void Pipe::ControlPoint::SetInnerDiameter
+(
+ double id
+) throw() {
+ assert(m_pipe != 0);
+
+ if(m_pipe != 0)
+ m_controlPoint->pp_id = id;
+}
+
+
+double Pipe::ControlPoint::OuterDiameter(void) const throw() {
+ assert(m_pipe != 0);
+
+ double ret;
+
+ if(m_pipe != 0)
+ ret = m_controlPoint->pp_od;
+
+ return ret;
+}
+
+
+void Pipe::ControlPoint::SetOuterDiameter
+(
+ double od
+) throw() {
+ assert(m_pipe != 0);
+
+ if(m_pipe != 0)
+ m_controlPoint->pp_od = od;
+}
+
+
+double Pipe::ControlPoint::BendRadius(void) const throw() {
+ assert(m_pipe != 0);
+
+ double ret;
+
+ if(m_pipe != 0)
+ ret = m_controlPoint->pp_bendradius;
+
+ return ret;
+}
+
+
+void Pipe::ControlPoint::SetBendRadius
+(
+ double br
+) throw() {
+ assert(m_pipe != 0);
+
+ if(m_pipe != 0)
+ m_controlPoint->pp_bendradius = br;
+}
+
+
+Pipe::ControlPoint Pipe::Get
+(
+ size_t index
+) throw() {
+ assert(index < Internal()->pipe_count);
+
+ Pipe::ControlPoint ret;
+ bu_list* seghead = &Internal()->pipe_segs_head;
+
+ if(index < Internal()->pipe_count) {
+ wdb_pipept* itr = BU_LIST_FIRST(wdb_pipept, seghead);
+
+ for (size_t count = 0; count < index; ++count)
+ itr = BU_LIST_NEXT(wdb_pipept, &itr->l);
+
+ ret = ControlPoint(Internal(), itr);
+ }
+
+ return ret;
+}
+
+
+Pipe::ControlPoint Pipe::AppendControlPoint
+(
+ const Vector3D& point,
+ double innerDiameter,
+ double outerDiameter,
+ double bendRadius
+) throw(bad_alloc) {
+ Pipe::ControlPoint ret;
+
+ if(!BU_SETJUMP) {
+ wdb_pipept* ctlPoint = static_cast<wdb_pipept*>(bu_calloc(1,
sizeof(wdb_pipept),"Pipe::AppendControlPoint: wdb_pipept"));
+
+ for(int i = 0; i < 3; i++)
+ ctlPoint->pp_coord[i] = point.coordinates[i];
+
+ ctlPoint->pp_id = innerDiameter;
+ ctlPoint->pp_od = outerDiameter;
+ ctlPoint->pp_bendradius = bendRadius;
+
+ BU_LIST_PUSH(&Internal()->pipe_segs_head, &ctlPoint->l);
+ Internal()->pipe_count += 1;
+
+ ret = ControlPoint(Internal(), ctlPoint);
+ }
+ else {
+ BU_UNSETJUMP;
+ throw bad_alloc("BRLAD::Pipe::AppendControlPoint");
+ }
+
+ return ret;
+}
+
+
+Pipe::ControlPoint Pipe::InsertControlPoint
+(
+ size_t index,
+ const Vector3D& point,
+ double innerDiameter,
+ double outerDiameter,
+ double bendRadius
+) throw(bad_alloc) {
+ assert(index <= Internal()->pipe_count);
+
+ Pipe::ControlPoint ret;
+
+ if (index <= Internal()->pipe_count) {
+ if(!BU_SETJUMP) {
+ wdb_pipept* ctlPoint = static_cast<wdb_pipept*>(bu_calloc(1,
sizeof(wdb_pipept),"Pipe::InsertControlPoint: wdb_pipept"));
+
+ for(int i = 0; i < 3; i++)
+ ctlPoint->pp_coord[i] = point.coordinates[i];
+
+ ctlPoint->pp_id = innerDiameter;
+ ctlPoint->pp_od = outerDiameter;
+ ctlPoint->pp_bendradius = bendRadius;
+
+ wdb_pipept* itr = BU_LIST_FIRST(wdb_pipept,
&Internal()->pipe_segs_head);
+
+ for (size_t count = 0; count < index; ++count)
+ itr = BU_LIST_NEXT(wdb_pipept, &itr->l);
+
+ BU_LIST_INSERT(&itr->l, &ctlPoint->l);
+ Internal()->pipe_count += 1;
+
+ ret = ControlPoint(Internal(), ctlPoint);
+ }
+ else {
+ BU_UNSETJUMP;
+ throw bad_alloc("BRLAD::Pipe::InsertControlPoint");
+ }
+ }
+
+ return ret;
+}
+
+
+void Pipe::DeleteControlPoint
+(
+ size_t index
+) throw() {
+ assert(index < Internal()->pipe_count);
+
+ if (index < Internal()->pipe_count) {
+ wdb_pipept* itr = BU_LIST_FIRST(wdb_pipept,
&Internal()->pipe_segs_head);
+
+ for (size_t count = 0; count < index; ++count)
+ itr = BU_LIST_NEXT(wdb_pipept, &itr->l);
+
+ BU_LIST_DEQUEUE(&(itr->l));
+ bu_free(&(itr->l), "BRLCAD::Pipe::DeleteControlPoint");
+
+ Internal()->pipe_count -= 1;
+ }
+}
+
+
+const Object& Pipe::operator=
+(
+ const Object& original
+) throw(bad_alloc) {
+ const Pipe* pipe = dynamic_cast<const Pipe*>(&original);
+ assert(pipe != 0);
+
+ if (pipe != 0)
+ *this = *pipe;
+
+ return *this;
+}
+
+
+Object* Pipe::Clone(void) const throw(bad_alloc, std::bad_alloc) {
+ return new Pipe(*this);
+}
+
+
+const char* Pipe::ClassName(void) throw() {
+ return "Pipe";
+}
+
+
+const char* Pipe::Type(void) const throw() {
+ return ClassName();
+}
+
+
+bool Pipe::IsValid(void) const throw() {
+ const rt_pipe_internal* pipe = Internal();
+
+ return ((bu_list_len(&pipe->pipe_segs_head) == pipe->pipe_count) &&
+ (rt_pipe_ck(&pipe->pipe_segs_head) == 0));
+}
+
+
+Pipe::Pipe
+(
+ resource* resp,
+ directory* pDir,
+ rt_db_internal* ip,
+ db_i* dbip
+) throw() : Object(resp, pDir, ip, dbip), m_internalp(0) {}
+
+
+const rt_pipe_internal* Pipe::Internal(void) const throw() {
+ const rt_pipe_internal* ret;
+
+ if (m_ip != 0)
+ ret = static_cast<const rt_pipe_internal*>(m_ip->idb_ptr);
+ else
+ ret = m_internalp;
+
+ RT_PIPE_CK_MAGIC(ret);
+
+ return ret;
+}
+
+
+rt_pipe_internal* Pipe::Internal(void) throw() {
+ rt_pipe_internal* ret;
+
+ if (m_ip != 0)
+ ret = static_cast<rt_pipe_internal*>(m_ip->idb_ptr);
+ else
+ ret = m_internalp;
+
+ RT_PIPE_CK_MAGIC(ret);
+
+ return ret;
+}
Property changes on: rt^3/trunk/src/coreInterface/Pipe.cpp
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: rt^3/trunk/src/libge/CMakeLists.txt
===================================================================
--- rt^3/trunk/src/libge/CMakeLists.txt 2015-08-09 22:29:30 UTC (rev 65862)
+++ rt^3/trunk/src/libge/CMakeLists.txt 2015-08-10 14:01:31 UTC (rev 65863)
@@ -42,8 +42,8 @@
#Set Include Dirs
include_directories (
${RT3_SOURCE_DIR}/include/brlcad
- ${BRLCAD_INCLUDE_DIRS}
- ${TCL_INCLUDE_PATH}
+ ${BRLCAD_INCLUDE_DIRS}
+ ${TCL_INCLUDE_PATH}
)
#set Source files
@@ -69,6 +69,7 @@
../coreInterface/ParabolicCylinder.cpp
../coreInterface/Paraboloid.cpp
../coreInterface/Particle.cpp
+ ../coreInterface/Pipe.cpp
../coreInterface/Torus.cpp
../coreInterface/Unknown.cpp
)
@@ -82,13 +83,13 @@
add_library(ge-static STATIC ${ge_SRCS})
install(TARGETS ge-static DESTINATION lib)
ENDIF(BUILD_STATIC_LIBS)
-
+
INSTALL(FILES
${RT3_SOURCE_DIR}/include/GeometryEngine.h
${RT3_SOURCE_DIR}/include/MinimalDatabase.h
${RT3_SOURCE_DIR}/include/MinimalObject.h
DESTINATION include)
-
+
SET(ge_inst_HDRS
${RT3_SOURCE_DIR}/include/brlcad/Arb8.h
${RT3_SOURCE_DIR}/include/brlcad/cicommon.h
@@ -109,6 +110,7 @@
${RT3_SOURCE_DIR}/include/brlcad/ParabolicCylinder.h
${RT3_SOURCE_DIR}/include/brlcad/Paraboloid.h
${RT3_SOURCE_DIR}/include/brlcad/Particle.h
+ ${RT3_SOURCE_DIR}/include/brlcad/Pipe.h
${RT3_SOURCE_DIR}/include/brlcad/Torus.h
${RT3_SOURCE_DIR}/include/brlcad/Unknown.h
)
Modified: rt^3/trunk/tests/coreInterface/CMakeLists.txt
===================================================================
--- rt^3/trunk/tests/coreInterface/CMakeLists.txt 2015-08-09 22:29:30 UTC
(rev 65862)
+++ rt^3/trunk/tests/coreInterface/CMakeLists.txt 2015-08-10 14:01:31 UTC
(rev 65863)
@@ -39,8 +39,12 @@
target_link_libraries(printTitle coreinterface)
set (ciTests_SRC
+ cone.cpp
+ ellipsoid.cpp
halfspace.cpp
+ pipe.cpp
primitives.cpp
+ sphere.cpp
)
add_executable(tester_ci_primitives ${ciTests_SRC})
Added: rt^3/trunk/tests/coreInterface/cone.cpp
===================================================================
--- rt^3/trunk/tests/coreInterface/cone.cpp (rev 0)
+++ rt^3/trunk/tests/coreInterface/cone.cpp 2015-08-10 14:01:31 UTC (rev
65863)
@@ -0,0 +1,332 @@
+/* C O N E . C P P
+ * BRL-CAD
+ *
+ * Copyright (c) 2014 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 file; see the file named COPYING for more
+ * information.
+ */
+/** @file cone.cpp
+ *
+ * BRL-CAD core C++ interface:
+ * truncated general cone (ID_TGC) database object implementation
+ *
+ * Origin -
+ * TNO (Netherlands)
+ * IABG mbH (Germany)
+ */
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <brlcad/Cone.h>
+#include "bn.h"
+#include "raytrace.h"
+#include "primitives.h"
+using namespace BRLCAD;
+
+#define VECTOR3D_EQUAL(a, b) VNEAR_EQUAL(a.coordinates, b.coordinates,
BN_TOL_DIST)
+
+#define VECTOR3D_MAGEQUAL(a, b) (NEAR_EQUAL(MAGNITUDE(a.coordinates), b,
BN_TOL_DIST))
+
+#define AXIS_ORTHOGONAL(a, b) \
+ (NEAR_ZERO(VDOT(a.coordinates, b.coordinates), RT_DOT_TOL))
+
+#define ADD_TEST(expression, allTestsPassed) \
+ if (!expression) { \
+ std::cout << "Failed test: " << #expression << std::endl; \
+ allTestsPassed = false; \
+ } else { \
+ std::cout << "Passed test: " << #expression << std::endl; \
+ }
+
+/* Test Helper */
+bool testHelper(const Cone &cone, const Vector3D &basePoint,
+ const Vector3D &height)
+{
+ const Vector3D setBasePoint = cone.BasePoint();
+ const Vector3D setHeight = cone.Height();
+ return(VECTOR3D_EQUAL(basePoint, setBasePoint) &&
+ VECTOR3D_EQUAL(height, setHeight));
+}
+
+/* Test default unit constructor */
+bool testConeUnitConstructor()
+{
+ Cone cone = Cone();
+ Vector3D basePoint = cone.BasePoint();
+ Vector3D height = cone.Height();
+ Vector3D actualBasePoint = Vector3D();
+ Vector3D actualHeight = Vector3D(0.0, 0.0, 1.0);
+ return(VECTOR3D_EQUAL(basePoint, actualBasePoint) &&
+ VECTOR3D_EQUAL(height, actualHeight) &&
+ AXIS_ORTHOGONAL(cone.SemiPrincipalAxis(0),
cone.SemiPrincipalAxis(1)));
+}
+
+/* Tests Cone's BasePoint function */
+bool testConeBasePoint(const Cone &cone, const double expectedX,
+ const double expectedY, const double expectedZ)
+{
+ Vector3D basePoint = cone.BasePoint();
+ Vector3D actualBasePoint = Vector3D(expectedX, expectedY, expectedZ);
+ return(VECTOR3D_EQUAL(basePoint, actualBasePoint));
+}
+
+/* Tests Cone's SetBasePoint function */
+bool testConeSetBasePoint(Cone cone, const Vector3D &basePoint)
+{
+ cone.SetBasePoint(basePoint);
+ Vector3D setBasePoint = cone.BasePoint();
+ return(VECTOR3D_EQUAL(basePoint, setBasePoint));
+}
+
+/* Tests Cone's Height function */
+bool testConeHeight(const Cone &cone, const double expectedX,
+ const double expectedY, const double expectedZ)
+{
+ Vector3D height = cone.Height();
+ Vector3D actualHeight = Vector3D(expectedX, expectedY, expectedZ);
+ return(VECTOR3D_EQUAL(height, actualHeight));
+}
+
+/* Tests Cone's SetHeight function */
+bool testConeSetHeight(Cone cone, const Vector3D height)
+{
+ cone.SetHeight(height);
+ Vector3D setHeight = cone.Height();
+ return(VECTOR3D_EQUAL(height, setHeight));
+}
+
+/* Tests Cone's SemiPrincipalAxis function */
+bool testConeSemiPrincipalAxis(const Cone &cone, const Vector3D
&actualSemiPrincipalAxis, size_t index)
+{
+ Vector3D semiPrincipalAxis = cone.SemiPrincipalAxis(index);
+ return(VECTOR3D_EQUAL(semiPrincipalAxis, actualSemiPrincipalAxis));
+}
+
+/* Tests Cone's SetSemiPrincipalAxis function */
+bool testConeSetSemiPrincipalAxis(Cone cone, const Vector3D
&semiPrincipalAxis, size_t index)
+{
+ cone.SetSemiPrincipalAxis(index, semiPrincipalAxis);
+ Vector3D setSemiPrincipalAxis = cone.SemiPrincipalAxis(index);
+ return(VECTOR3D_EQUAL(semiPrincipalAxis, setSemiPrincipalAxis));
+}
+
+/* Tests Cone's ClassName function */
+bool testConeClassName(const Cone &cone)
+{
+ const std::string coneClassName = "Cone";
+ const std::string actualClassName = cone.ClassName();
+ return(coneClassName.compare(actualClassName) == 0);
+}
+
+/* Tests Cone's Type function */
+bool testConeType(const Cone &cone)
+{
+ return(cone.Type() == cone.ClassName());
+}
+
+/* Tests Cone's Set function (Right Elliptical Cylinder) */
+bool testConeSetREC(Cone cone, const Vector3D &basePoint,
+ const Vector3D &height, const Vector3D &semiPrincipalAxisA,
+ const Vector3D &semiPrincipalAxisB)
+{
+ cone.Set(basePoint, height, semiPrincipalAxisA, semiPrincipalAxisB);
+ const Vector3D setSemiPrincipalAxisA = cone.SemiPrincipalAxis(0);
+ const Vector3D setSemiPrincipalAxisB = cone.SemiPrincipalAxis(1);
+ bool helper = testHelper((const Cone &)cone, basePoint, height);
+ return (helper &&
+ VECTOR3D_EQUAL(semiPrincipalAxisA, setSemiPrincipalAxisA) &&
+ VECTOR3D_EQUAL(semiPrincipalAxisB, setSemiPrincipalAxisB) &&
+ AXIS_ORTHOGONAL(setSemiPrincipalAxisA, setSemiPrincipalAxisB));
+}
+
+/* Tests Cone's Set function (Truncated General Cone) */
+bool testConeSetTGC(Cone cone, const Vector3D &basePoint,
+ const Vector3D &height, const Vector3D &semiPrincipalAxisA,
+ const Vector3D &semiPrincipalAxisB, const double ratioCtoA,
+ const double ratioDtoB)
+{
+ bool flag = false;
+ cone.Set(basePoint, height, semiPrincipalAxisA, semiPrincipalAxisB,
+ ratioCtoA, ratioDtoB);
+ const Vector3D setSemiPrincipalAxisA = cone.SemiPrincipalAxis(0);
+ const Vector3D setSemiPrincipalAxisB = cone.SemiPrincipalAxis(1);
+ const Vector3D setSemiPrincipalAxisC = cone.SemiPrincipalAxis(2);
+ const Vector3D setSemiPrincipalAxisD = cone.SemiPrincipalAxis(3);
+ double setRatioCtoA, setRatioDtoB;
+ for(int i = 0; i < 3; i++) {
+ if(!EQUAL(setSemiPrincipalAxisA.coordinates[i], 0.0)) {
+ setRatioCtoA = setSemiPrincipalAxisC.coordinates[i] /
setSemiPrincipalAxisA.coordinates[i];
+ flag = true;
+ break;
+ } /* If flag remains false, it means semi principal axis has zero
magnitude */
+ }
+ if(flag) {
+ for(int i = 0; i < 3; i++) {
+ if(!EQUAL(setSemiPrincipalAxisB.coordinates[i], 0.0)) {
+ setRatioDtoB = setSemiPrincipalAxisD.coordinates[i] /
setSemiPrincipalAxisB.coordinates[i];
+ flag = true;
+ break;
+ } /* If flag remains false, it means semi principal axis has zero
magnitude */
+ }
+ }
+ bool helper = testHelper((const Cone &)cone, basePoint, height);
+ return (flag && helper &&
+ EQUAL(setRatioCtoA, ratioCtoA) &&
+ EQUAL(setRatioDtoB, ratioDtoB) &&
+ VECTOR3D_EQUAL(semiPrincipalAxisA, setSemiPrincipalAxisA) &&
+ VECTOR3D_EQUAL(semiPrincipalAxisB, setSemiPrincipalAxisB) &&
+ AXIS_ORTHOGONAL(setSemiPrincipalAxisA, setSemiPrincipalAxisB));
+}
+
+/* Tests Cone's Set function (Truncated Elliptical Cone) */
+bool testConeSetTEC(Cone cone, const Vector3D &basePoint,
+ const Vector3D &height, const Vector3D &semiPrincipalAxisA,
+ const Vector3D &semiPrincipalAxisB, const double scale)
+{
+ bool flag = false;
+ cone.Set(basePoint, height, semiPrincipalAxisA, semiPrincipalAxisB,
+ scale);
+ const Vector3D setSemiPrincipalAxisA = cone.SemiPrincipalAxis(0);
+ const Vector3D setSemiPrincipalAxisB = cone.SemiPrincipalAxis(1);
+ const Vector3D setSemiPrincipalAxisC = cone.SemiPrincipalAxis(2);
+ double setScale;
+ for(int i = 0; i < 3; i++) {
+ if(!EQUAL(setSemiPrincipalAxisA.coordinates[i], 0.0)) {
+ setScale = setSemiPrincipalAxisC.coordinates[i] /
setSemiPrincipalAxisA.coordinates[i];
+ flag = true;
+ break;
+ } /* If flag remains false, it means semi principal axis has zero
magnitude */
+ }
+ bool helper = testHelper((const Cone &)cone, basePoint, height);
+ return (flag && helper &&
+ EQUAL(setScale, scale) &&
+ VECTOR3D_EQUAL(semiPrincipalAxisA, setSemiPrincipalAxisA) &&
+ VECTOR3D_EQUAL(semiPrincipalAxisB, setSemiPrincipalAxisB) &&
+ AXIS_ORTHOGONAL(setSemiPrincipalAxisA, setSemiPrincipalAxisB));
+}
+
+/* Tests Cone's Set function (Truncated Right Cone) */
+bool testConeSetTRC(Cone cone, const Vector3D &basePoint,
+ const Vector3D &height, const double radiusBase,
+ const double radiusTop)
+{
+ cone.Set(basePoint, height, radiusBase, radiusTop);
+ const Vector3D semiPrincipalAxisA = cone.SemiPrincipalAxis(0);
+ const Vector3D semiPrincipalAxisB = cone.SemiPrincipalAxis(1);
+ const Vector3D semiPrincipalAxisC = cone.SemiPrincipalAxis(2);
+ const Vector3D semiPrincipalAxisD = cone.SemiPrincipalAxis(3);
+ Vector3D actualSemiPrincipalAxisC, actualSemiPrincipalAxisD;
+ const double scale = radiusTop / radiusBase;
+ for(int i = 0; i < 3; i++) {
+ actualSemiPrincipalAxisC.coordinates[i] =
semiPrincipalAxisA.coordinates[i] * scale;
+ actualSemiPrincipalAxisD.coordinates[i] =
semiPrincipalAxisB.coordinates[i] * scale;
+ }
+ bool helper = testHelper((const Cone &)cone, basePoint, height);
+ return(helper &&
+ VECTOR3D_EQUAL(semiPrincipalAxisC, actualSemiPrincipalAxisC) &&
+ VECTOR3D_EQUAL(semiPrincipalAxisD, actualSemiPrincipalAxisD) &&
+ AXIS_ORTHOGONAL(semiPrincipalAxisA, semiPrincipalAxisB));
+}
+
+/* Tests Cone's Set function (Right Circular Cylinder) */
+bool testConeSetRCC(Cone cone, const Vector3D &basePoint,
+ const Vector3D &height, const double radius)
+{
+ cone.Set(basePoint, height, radius);
+ const Vector3D semiPrincipalAxisA = cone.SemiPrincipalAxis(0);
+ const Vector3D semiPrincipalAxisB = cone.SemiPrincipalAxis(1);
+ const Vector3D semiPrincipalAxisC = cone.SemiPrincipalAxis(2);
+ const Vector3D semiPrincipalAxisD = cone.SemiPrincipalAxis(3);
+ bool helper = testHelper((const Cone &)cone, basePoint, height);
+ return(helper &&
+ VECTOR3D_EQUAL(semiPrincipalAxisC, semiPrincipalAxisA) &&
+ VECTOR3D_EQUAL(semiPrincipalAxisD, semiPrincipalAxisB) &&
+ AXIS_ORTHOGONAL(semiPrincipalAxisA, semiPrincipalAxisB));
+}
+
+/* Tests Cone's Clone function */
+bool testConeClone(Cone cone)
+{
+ Cone clonedCone;
+ clonedCone = *static_cast<Cone *>(cone.Clone());
+ return clonedCone.IsValid();
+}
+
+/* Runs all the Cone tests */
+void test_cone(Database& database)
+{
+ std::vector<Vector3D> semiPrincipalAxis;
+ Cone cone;
+ const Vector3D basePoint = Vector3D();
+ const Vector3D height = Vector3D(0.0, 0.0, 1.0);
+ Vector3D semiPrincipalAxisA, semiPrincipalAxisB;
+ const double radius = 1.0;
+ cone.Set(basePoint, height, radius);
+ for(size_t i = 0; i < 3; i++) {
+ semiPrincipalAxis.push_back(cone.SemiPrincipalAxis(i));
+ }
+ bool allConeTestsPassed = true;
+
+ /* Run tests */
+ if(cone.IsValid()) {
+ std::cout << "Starting Cone Unit testing . . ." << std::endl;
+ ADD_TEST(testConeUnitConstructor(), allConeTestsPassed);
+ ADD_TEST(testConeBasePoint(cone, 0.0, 0.0, 0.0), allConeTestsPassed);
+ ADD_TEST(testConeSetBasePoint(cone, basePoint), allConeTestsPassed);
+ ADD_TEST(testConeHeight(cone, 0.0, 0.0, 1.0), allConeTestsPassed);
+ ADD_TEST(testConeSetHeight(cone, height), allConeTestsPassed);
+ for(size_t i = 0; i < 3; i++) {
+ ADD_TEST(testConeSemiPrincipalAxis(cone, semiPrincipalAxis[i], i),
allConeTestsPassed);
+ }
+ for(size_t i = 0; i < 3; i++) {
+ ADD_TEST(testConeSetSemiPrincipalAxis(cone, semiPrincipalAxis[i],
i), allConeTestsPassed);
+ }
+ ADD_TEST(testConeClassName(cone), allConeTestsPassed);
+ ADD_TEST(testConeType(cone), allConeTestsPassed);
+ semiPrincipalAxisA = Vector3D(1.0, 0.0, 0.0);
+ semiPrincipalAxisB = Vector3D(0.0, 2.0, 0.0);
+ ADD_TEST(testConeSetREC(cone, basePoint, height, semiPrincipalAxisA,
+ semiPrincipalAxisB), allConeTestsPassed);
+ ADD_TEST(testConeSetTGC(cone, basePoint, height, semiPrincipalAxisA,
+ semiPrincipalAxisB, 2.0, 2.0), allConeTestsPassed);
+ ADD_TEST(testConeSetTEC(cone, basePoint, height, semiPrincipalAxisA,
+ semiPrincipalAxisB, 1.5), allConeTestsPassed);
+ ADD_TEST(testConeSetTRC(cone, basePoint, height, 4.0, 1.0),
allConeTestsPassed);
+ ADD_TEST(testConeSetRCC(cone, basePoint, height, 2.5),
allConeTestsPassed);
+ ADD_TEST(testConeClone(cone), allConeTestsPassed);
+ } else {
+ std::cout << "Default Cone is not valid" << std::endl;
+ allConeTestsPassed = false;
+ }
+
+ /* We only add the cone to the database if it failed no tests */
+ if(allConeTestsPassed) {
+ std::cout << "All Cone tests passed; adding object to database . . ."
<< std::endl;
+ database.Add(cone);
+ }
+}
+
+
+/*
+ * Local Variables:
+ * mode: C++
+ * tab-width: 8
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: rt^3/trunk/tests/coreInterface/cone.cpp
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: rt^3/trunk/tests/coreInterface/ellipsoid.cpp
===================================================================
--- rt^3/trunk/tests/coreInterface/ellipsoid.cpp
(rev 0)
+++ rt^3/trunk/tests/coreInterface/ellipsoid.cpp 2015-08-10 14:01:31 UTC
(rev 65863)
@@ -0,0 +1,260 @@
+/* E L L I P S O I D . C P P
+ * BRL-CAD
+ *
+ * Copyright (c) 2014 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 file; see the file named COPYING for more
+ * information.
+ */
+/** @file ellipsoid.cpp
+ *
+ * C++ core interface Ellipsoid test
+ *
+ */
+
+#include <iostream>
+
+#include "brlcad/Ellipsoid.h"
+
+#include "primitives.h"
+
+#include "vmath.h"
+#include "bn/tol.h"
+#include "raytrace.h"
+
+#define VECTOR3D_EQUAL(a, b) VNEAR_EQUAL(a.coordinates, b.coordinates,
BN_TOL_DIST)
+
+#define VECTOR3D_MAGEQUAL(a, b) (NEAR_EQUAL(MAGNITUDE(a.coordinates), b,
BN_TOL_DIST))
+
+#define AXIS_ORTHOGONAL(a, b, c) \
+ (NEAR_ZERO(VDOT(a.coordinates, b.coordinates), RT_DOT_TOL) && \
+ NEAR_ZERO(VDOT(b.coordinates, c.coordinates), RT_DOT_TOL) && \
+ NEAR_ZERO(VDOT(a.coordinates, c.coordinates), RT_DOT_TOL))
+
+#define ADD_TEST(expression, allTestsPassed) \
+ if (!expression) { \
+ std::cout << "Failed test: " << #expression << std::endl; \
+ allTestsPassed = false; \
+ } else { \
+ std::cout << "Passed test: " << #expression << std::endl; \
+ }
+
+
+bool testUnitEllipsoidConstructor()
+{
+ BRLCAD::Ellipsoid ellipsoid;
+ BRLCAD::Vector3D semiPrincipalAxisA = ellipsoid.SemiPrincipalAxis(0);
+ BRLCAD::Vector3D semiPrincipalAxisB = ellipsoid.SemiPrincipalAxis(1);
+ BRLCAD::Vector3D semiPrincipalAxisC = ellipsoid.SemiPrincipalAxis(2);
+ return (VECTOR3D_EQUAL(ellipsoid.Center(), BRLCAD::Vector3D()) &&
+ VECTOR3D_MAGEQUAL(semiPrincipalAxisA, 1) &&
+ VECTOR3D_MAGEQUAL(semiPrincipalAxisB, 1) &&
+ VECTOR3D_MAGEQUAL(semiPrincipalAxisC, 1) &&
+ AXIS_ORTHOGONAL(semiPrincipalAxisA,
+ semiPrincipalAxisB,
+ semiPrincipalAxisC));
+}
+
+bool testGeneralEllipsoidConstructor(BRLCAD::Vector3D center,
+ BRLCAD::Vector3D semiPrincipalAxisA,
+ BRLCAD::Vector3D semiPrincipalAxisB,
+ BRLCAD::Vector3D semiPrincipalAxisC)
+{
+ BRLCAD::Ellipsoid ellipsoid(center, semiPrincipalAxisA,
semiPrincipalAxisB, semiPrincipalAxisC);
+ return (VECTOR3D_EQUAL(ellipsoid.Center(), center) &&
+ VECTOR3D_EQUAL(ellipsoid.SemiPrincipalAxis(0), semiPrincipalAxisA)
&&
+ VECTOR3D_EQUAL(ellipsoid.SemiPrincipalAxis(1), semiPrincipalAxisB)
&&
+ VECTOR3D_EQUAL(ellipsoid.SemiPrincipalAxis(2), semiPrincipalAxisC));
+}
+
+bool testBodyOfRevolutionConstructor(BRLCAD::Vector3D center,
+ BRLCAD::Vector3D semiPrincipalAxis,
+ const double radius)
+{
+ BRLCAD::Ellipsoid ellipsoid(center, semiPrincipalAxis, radius);
+ BRLCAD::Vector3D actualSemiPrincipalAxisA = ellipsoid.SemiPrincipalAxis(0);
+ BRLCAD::Vector3D actualSemiPrincipalAxisB = ellipsoid.SemiPrincipalAxis(1);
+ BRLCAD::Vector3D actualSemiPrincipalAxisC = ellipsoid.SemiPrincipalAxis(2);
+
+ return (VECTOR3D_EQUAL(ellipsoid.Center(), center) &&
+ VECTOR3D_EQUAL(actualSemiPrincipalAxisA, semiPrincipalAxis) &&
+ VECTOR3D_MAGEQUAL(actualSemiPrincipalAxisB, radius) &&
+ VECTOR3D_MAGEQUAL(actualSemiPrincipalAxisC, radius) &&
+ AXIS_ORTHOGONAL(actualSemiPrincipalAxisA,
+ actualSemiPrincipalAxisB,
+ actualSemiPrincipalAxisC));
+}
+
+bool testSphereConstructor(BRLCAD::Vector3D center, const double radius)
+{
+ BRLCAD::Ellipsoid ellipsoid(center, radius);
+ BRLCAD::Vector3D actualSemiPrincipalAxisA = ellipsoid.SemiPrincipalAxis(0);
+ BRLCAD::Vector3D actualSemiPrincipalAxisB = ellipsoid.SemiPrincipalAxis(1);
+ BRLCAD::Vector3D actualSemiPrincipalAxisC = ellipsoid.SemiPrincipalAxis(2);
+ return (VECTOR3D_EQUAL(ellipsoid.Center(), center) &&
+ VECTOR3D_MAGEQUAL(actualSemiPrincipalAxisA, radius) &&
+ VECTOR3D_MAGEQUAL(actualSemiPrincipalAxisB, radius) &&
+ VECTOR3D_MAGEQUAL(actualSemiPrincipalAxisC, radius) &&
+ AXIS_ORTHOGONAL(actualSemiPrincipalAxisA,
+ actualSemiPrincipalAxisB,
+ actualSemiPrincipalAxisC));
+}
+
+bool testSetCenter(BRLCAD::Vector3D center)
+{
+ BRLCAD::Ellipsoid ellipsoid;
+ ellipsoid.SetCenter(center);
+ return (VECTOR3D_EQUAL(ellipsoid.Center(), center));
+}
+
+bool testSetSemiPrincipalAxis(size_t index, BRLCAD::Vector3D axis)
+{
+ BRLCAD::Ellipsoid ellipsoid;
+ ellipsoid.SetSemiPrincipalAxis(index, axis);
+ return (VECTOR3D_EQUAL(ellipsoid.SemiPrincipalAxis(index), axis));
+}
+
+bool testGeneralSet(BRLCAD::Vector3D center, BRLCAD::Vector3D
semiPrincipalAxisA,
+ BRLCAD::Vector3D semiPrincipalAxisB, BRLCAD::Vector3D
semiPrincipalAxisC)
+{
+ BRLCAD::Ellipsoid ellipsoid;
+ ellipsoid.Set(center, semiPrincipalAxisA, semiPrincipalAxisB,
semiPrincipalAxisC);
+ return (VECTOR3D_EQUAL(ellipsoid.Center(), center) &&
+ VECTOR3D_EQUAL(ellipsoid.SemiPrincipalAxis(0), semiPrincipalAxisA)
&&
+ VECTOR3D_EQUAL(ellipsoid.SemiPrincipalAxis(1), semiPrincipalAxisB)
&&
+ VECTOR3D_EQUAL(ellipsoid.SemiPrincipalAxis(2), semiPrincipalAxisC));
+}
+
+bool testBodyOfRevolutionSet(BRLCAD::Vector3D center,
+ BRLCAD::Vector3D semiPrincipalAxis, const double radius)
+{
+ BRLCAD::Ellipsoid ellipsoid;
+ ellipsoid.Set(center, semiPrincipalAxis, radius);
+ BRLCAD::Vector3D actualSemiPrincipalAxisA = ellipsoid.SemiPrincipalAxis(0);
+ BRLCAD::Vector3D actualSemiPrincipalAxisB = ellipsoid.SemiPrincipalAxis(1);
+ BRLCAD::Vector3D actualSemiPrincipalAxisC = ellipsoid.SemiPrincipalAxis(2);
+
+ return (VECTOR3D_EQUAL(ellipsoid.Center(), center) &&
+ VECTOR3D_EQUAL(actualSemiPrincipalAxisA, semiPrincipalAxis) &&
+ VECTOR3D_MAGEQUAL(actualSemiPrincipalAxisB, radius) &&
+ VECTOR3D_MAGEQUAL(actualSemiPrincipalAxisC, radius) &&
+ AXIS_ORTHOGONAL(actualSemiPrincipalAxisA,
+ actualSemiPrincipalAxisB,
+ actualSemiPrincipalAxisC));
+}
+
+bool testSetFocals(BRLCAD::Vector3D focalA, BRLCAD::Vector3D focalB, const
double majorAxisLength)
+{
+ BRLCAD::Ellipsoid ellipsoid;
+ ellipsoid.SetFocals(focalA, focalB, majorAxisLength);
+ BRLCAD::Vector3D actualSemiPrincipalAxisA = ellipsoid.SemiPrincipalAxis(0);
+ BRLCAD::Vector3D actualSemiPrincipalAxisB = ellipsoid.SemiPrincipalAxis(1);
+ BRLCAD::Vector3D actualSemiPrincipalAxisC = ellipsoid.SemiPrincipalAxis(2);
+
+ BRLCAD::Vector3D fociDistance;
+ VADD2(fociDistance.coordinates, focalA.coordinates, focalB.coordinates);
+
+ BRLCAD::Vector3D expectedCenter;
+ VSCALE(expectedCenter.coordinates, fociDistance.coordinates, 0.5);
+
+ double expectedMinorAxesLengths;
+ expectedMinorAxesLengths = sqrt(majorAxisLength * majorAxisLength -
MAGSQ(fociDistance.coordinates) * 0.25);
+
+ return (VECTOR3D_EQUAL(ellipsoid.Center(), expectedCenter) &&
+ VECTOR3D_MAGEQUAL(actualSemiPrincipalAxisA, majorAxisLength) &&
+ VECTOR3D_MAGEQUAL(actualSemiPrincipalAxisB,
expectedMinorAxesLengths) &&
+ VECTOR3D_MAGEQUAL(actualSemiPrincipalAxisC,
expectedMinorAxesLengths) &&
+ AXIS_ORTHOGONAL(actualSemiPrincipalAxisA,
+ actualSemiPrincipalAxisB,
+ actualSemiPrincipalAxisC));
+}
+
+bool testSetSphere(BRLCAD::Vector3D center, const double radius)
+{
+ BRLCAD::Ellipsoid ellipsoid;
+ ellipsoid.SetSphere(center, radius);
+ BRLCAD::Vector3D actualSemiPrincipalAxisA = ellipsoid.SemiPrincipalAxis(0);
+ BRLCAD::Vector3D actualSemiPrincipalAxisB = ellipsoid.SemiPrincipalAxis(1);
+ BRLCAD::Vector3D actualSemiPrincipalAxisC = ellipsoid.SemiPrincipalAxis(2);
+
+ return (VECTOR3D_EQUAL(ellipsoid.Center(), center) &&
+ VECTOR3D_MAGEQUAL(actualSemiPrincipalAxisA, radius) &&
+ VECTOR3D_MAGEQUAL(actualSemiPrincipalAxisB, radius) &&
+ VECTOR3D_MAGEQUAL(actualSemiPrincipalAxisC, radius) &&
+ AXIS_ORTHOGONAL(actualSemiPrincipalAxisA,
+ actualSemiPrincipalAxisB,
+ actualSemiPrincipalAxisC));
+}
+
+bool testClone(BRLCAD::Vector3D center, BRLCAD::Vector3D semiPrincipalAxisA,
+ BRLCAD::Vector3D semiPrincipalAxisB, BRLCAD::Vector3D
semiPrincipalAxisC)
+{
+ BRLCAD::Ellipsoid original(center, semiPrincipalAxisA, semiPrincipalAxisB,
semiPrincipalAxisC);
+ BRLCAD::Ellipsoid cloned =
*static_cast<BRLCAD::Ellipsoid*>(original.Clone());
+ return (VECTOR3D_EQUAL(cloned.Center(), center) &&
+ VECTOR3D_EQUAL(cloned.SemiPrincipalAxis(0), semiPrincipalAxisA) &&
+ VECTOR3D_EQUAL(cloned.SemiPrincipalAxis(1), semiPrincipalAxisB) &&
+ VECTOR3D_EQUAL(cloned.SemiPrincipalAxis(2), semiPrincipalAxisC));
+}
+
+void test_ellipsoid(BRLCAD::Database& database)
+{
+ BRLCAD::Ellipsoid ellipsoid;
+ ellipsoid.SetName("Ellipsoid.s");
+
+ bool allEllipsoidTestsPassed = true;
+
+ if (ellipsoid.IsValid()) {
+ std::cout << "Starting Ellipsoid Unit testing . . ." << std::endl;
+ ADD_TEST(testUnitEllipsoidConstructor(), allEllipsoidTestsPassed);
+ ADD_TEST(testGeneralEllipsoidConstructor(BRLCAD::Vector3D(0, 0, 0),
+ BRLCAD::Vector3D(2, 0, 0), BRLCAD::Vector3D(0, 3, 0),
BRLCAD::Vector3D(4, 2, 3)), allEllipsoidTestsPassed);
+ ADD_TEST(testBodyOfRevolutionConstructor(BRLCAD::Vector3D(0, 0, 0),
+ BRLCAD::Vector3D(2, 0, 0), 5), allEllipsoidTestsPassed);
+ ADD_TEST(testSphereConstructor(BRLCAD::Vector3D(0, 0, 0), 5),
allEllipsoidTestsPassed);
+ ADD_TEST(testSetCenter(BRLCAD::Vector3D(0, 0, 0)),
allEllipsoidTestsPassed);
+ ADD_TEST(testSetSemiPrincipalAxis(0, BRLCAD::Vector3D(2, 0, 0)),
allEllipsoidTestsPassed);
+ ADD_TEST(testSetSemiPrincipalAxis(1, BRLCAD::Vector3D(0, 3, 0)),
allEllipsoidTestsPassed);
+ ADD_TEST(testSetSemiPrincipalAxis(2, BRLCAD::Vector3D(4, 2, 3)),
allEllipsoidTestsPassed);
+ ADD_TEST(testGeneralSet(BRLCAD::Vector3D(0, 0, 0), BRLCAD::Vector3D(2,
0, 0),
+ BRLCAD::Vector3D(0, 3, 0), BRLCAD::Vector3D(4, 2, 3)),
allEllipsoidTestsPassed);
+ ADD_TEST(testBodyOfRevolutionSet(BRLCAD::Vector3D(0, 0, 0),
+ BRLCAD::Vector3D(2, 0, 0), 5), allEllipsoidTestsPassed);
+ ADD_TEST(testSetFocals(BRLCAD::Vector3D(-1, 0, 0),
+ BRLCAD::Vector3D(0, 1, 0), 10), allEllipsoidTestsPassed);
+ ADD_TEST(testSetSphere(BRLCAD::Vector3D(0, 0, 0), 5),
allEllipsoidTestsPassed);
+ ADD_TEST(testClone(BRLCAD::Vector3D(0, 0, 0), BRLCAD::Vector3D(2, 0, 0),
+ BRLCAD::Vector3D(0, 3, 0), BRLCAD::Vector3D(4, 2, 3)),
allEllipsoidTestsPassed);
+ } else {
+ std::cout << "default Ellipsoid not valid" << std::endl;
+ allEllipsoidTestsPassed = false;
+ }
+
+ if(allEllipsoidTestsPassed) {
+ std::cout << "All Ellipsoid tests passed; adding object to database . .
." << std::endl;
+ database.Add(ellipsoid);
+ }
+}
+
+
+/*
+ * Local Variables:
+ * mode: C++
+ * tab-width: 8
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: rt^3/trunk/tests/coreInterface/ellipsoid.cpp
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: rt^3/trunk/tests/coreInterface/halfspace.cpp
===================================================================
--- rt^3/trunk/tests/coreInterface/halfspace.cpp 2015-08-09 22:29:30 UTC
(rev 65862)
+++ rt^3/trunk/tests/coreInterface/halfspace.cpp 2015-08-10 14:01:31 UTC
(rev 65863)
@@ -1,4 +1,4 @@
- /* H A L F S P A C E . C P P
+/* H A L F S P A C E . C P P
* BRL-CAD
*
* Copyright (c) 2014 United States Government as represented by
@@ -45,14 +45,15 @@
std::cout << "Halfspace not valid" << std::endl;
}
else
- std::cout << "default Halfspace not valid" << std::endl;
+ std::cout << "default Halfspace not valid" << std::endl;
}
/*
* Local Variables:
- * mode: C
+ * mode: C++
* tab-width: 8
+ * c-basic-offset: 4
* indent-tabs-mode: t
* c-file-style: "stroustrup"
* End:
Added: rt^3/trunk/tests/coreInterface/pipe.cpp
===================================================================
--- rt^3/trunk/tests/coreInterface/pipe.cpp (rev 0)
+++ rt^3/trunk/tests/coreInterface/pipe.cpp 2015-08-10 14:01:31 UTC (rev
65863)
@@ -0,0 +1,331 @@
+/* P I P E . C P P
+ * BRL-CAD
+ *
+ * Copyright (c) 2015 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 file; see the file named COPYING for more
+ * information.
+ */
+/** @file pipe.cpp
+ *
+ * BRL-CAD core C++ interface :
+ * Unit tests for Pipe class implementation
+ *
+ */
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <brlcad/Pipe.h>
+#include "bn.h"
+#include "primitives.h"
+using namespace BRLCAD;
+
+#define VECTOR3D_EQUAL(a, b) VNEAR_EQUAL(a.coordinates, b.coordinates,
BN_TOL_DIST)
+
+#define ADD_TEST(expression, allTestsPassed) \
+ if (!expression) { \
+ std::cout << "Failed test: " << #expression << std::endl; \
+ allTestsPassed = false; \
+ } else { \
+ std::cout << "Passed test: " << #expression << std::endl; \
+ }
+
+Pipe makePipe()
+{
+ Pipe p = Pipe();
+ Pipe::ControlPoint cp;
+ const Vector3D p1 = Vector3D(500.0, 500.0, 50.0);
+ const Vector3D p2 = Vector3D(500.0, -500.0, 150.0);
+ const Vector3D p3 = Vector3D(-500.0, -500.0, 250.0);
+ const Vector3D p4 = Vector3D(-500.0, 500.0, 350.0);
+ const double innerDiameter = 0.0;
+ const double outerDiameter = 200.0;
+ const double bendRadius = 500.0;
+ cp = p.AppendControlPoint(p1, innerDiameter, outerDiameter, bendRadius);
+ cp = p.AppendControlPoint(p2, innerDiameter, outerDiameter, bendRadius);
+ cp = p.AppendControlPoint(p3, innerDiameter, outerDiameter, bendRadius);
+ cp = p.AppendControlPoint(p4, innerDiameter, outerDiameter, bendRadius);
+ return p;
+}
+
+bool testPipeInsertControlPointMethod()
+{
+ Pipe p = Pipe();
+ Pipe::ControlPoint cp;
+ const Vector3D point = Vector3D(1.0, 1.0, 1.0);
+ double innerDiameter = 3.0;
+ double outerDiameter = 6.0;
+ double bendRadius = 4.0; /* bendRadius > outerDiameter / 2 */
+ cp = p.InsertControlPoint(0, point, innerDiameter, outerDiameter,
bendRadius);
+ const Vector3D setPoint = cp.Point();
+ double setInnerDiameter = cp.InnerDiameter();
+ double setOuterDiameter = cp.OuterDiameter();
+ double setBendRadius = cp.BendRadius();
+ return(VECTOR3D_EQUAL(point, setPoint) &&
+ EQUAL(innerDiameter, setInnerDiameter) &&
+ EQUAL(outerDiameter, setOuterDiameter) &&
+ EQUAL(bendRadius, setBendRadius));
+}
+
+bool testPipeAppendControlPointMethod()
+{
+ Pipe p = Pipe();
+ Pipe::ControlPoint cp;
+ const Vector3D point = Vector3D(1.0, 1.0, 1.0);
+ double innerDiameter = 3.0;
+ double outerDiameter = 6.0;
+ double bendRadius = 4.0; /* bendRadius > outerDiameter / 2 */
+ cp = p.AppendControlPoint(point, innerDiameter, outerDiameter, bendRadius);
+ const Vector3D setPoint = cp.Point();
+ double setInnerDiameter = cp.InnerDiameter();
+ double setOuterDiameter = cp.OuterDiameter();
+ double setBendRadius = cp.BendRadius();
+ return(VECTOR3D_EQUAL(point, setPoint) &&
+ EQUAL(innerDiameter, setInnerDiameter) &&
+ EQUAL(outerDiameter, setOuterDiameter) &&
+ EQUAL(bendRadius, setBendRadius));
+}
+
+bool testPipeGetControlPointMethod()
+{
+ Pipe p = Pipe();
+ Pipe::ControlPoint cp;
+ Vector3D point = Vector3D(1.0, 1.0, 1.0);
+ double innerDiameter = 3.0;
+ double outerDiameter = 6.0;
+ double bendRadius = 4.0; /* bendRadius > outerDiameter / 2 */
+ cp = p.AppendControlPoint(point, innerDiameter, outerDiameter, bendRadius);
+ point = Vector3D(10.0, 10.0, 5.0);
+ innerDiameter = 3.0;
+ outerDiameter = 6.0;
+ bendRadius = 5.0; /* bendRadius > outerDiameter / 2 */
+ cp = p.AppendControlPoint(point, innerDiameter, outerDiameter, bendRadius);
+ cp = p.Get(1);
+ const Vector3D setPoint = cp.Point();
+ double setInnerDiameter = cp.InnerDiameter();
+ double setOuterDiameter = cp.OuterDiameter();
+ double setBendRadius = cp.BendRadius();
+ return(VECTOR3D_EQUAL(point, setPoint) &&
+ EQUAL(innerDiameter, setInnerDiameter) &&
+ EQUAL(outerDiameter, setOuterDiameter) &&
+ EQUAL(bendRadius, setBendRadius));
+}
+
+bool testControlPointGetPointMethod()
+{
+ Pipe p = Pipe();
+ Pipe::ControlPoint cp;
+ const Vector3D point = Vector3D(1.0, 1.0, 1.0);
+ double innerDiameter = 3.0;
+ double outerDiameter = 6.0;
+ double bendRadius = 4.0; /* bendRadius > outerDiameter / 2 */
+ cp = p.AppendControlPoint(point, innerDiameter, outerDiameter, bendRadius);
+ const Vector3D setPoint = cp.Point();
+ return(VECTOR3D_EQUAL(point, setPoint));
+}
+
+bool testControlPointGetInnerDiameterMethod()
+{
+ Pipe p = Pipe();
+ Pipe::ControlPoint cp;
+ const Vector3D point = Vector3D(1.0, 1.0, 1.0);
+ double innerDiameter = 3.0;
+ double outerDiameter = 6.0;
+ double bendRadius = 4.0; /* bendRadius > outerDiameter / 2 */
+ cp = p.AppendControlPoint(point, innerDiameter, outerDiameter, bendRadius);
+ double setInnerDiameter = cp.InnerDiameter();
+ return(EQUAL(innerDiameter, setInnerDiameter));
+}
+
+bool testControlPointGetOuterDiameterMethod()
+{
+ Pipe p = Pipe();
+ Pipe::ControlPoint cp;
+ const Vector3D point = Vector3D(1.0, 1.0, 1.0);
+ double innerDiameter = 3.0;
+ double outerDiameter = 6.0;
+ double bendRadius = 4.0; /* bendRadius > outerDiameter / 2 */
+ cp = p.AppendControlPoint(point, innerDiameter, outerDiameter, bendRadius);
+ double setOuterDiameter = cp.OuterDiameter();
+ return(EQUAL(outerDiameter, setOuterDiameter));
+}
+
+bool testControlPointGetBendRadius()
+{
+ Pipe p = Pipe();
+ Pipe::ControlPoint cp;
+ const Vector3D point = Vector3D(1.0, 1.0, 1.0);
+ double innerDiameter = 3.0;
+ double outerDiameter = 6.0;
+ double bendRadius = 4.0; /* bendRadius > outerDiameter / 2 */
+ cp = p.AppendControlPoint(point, innerDiameter, outerDiameter, bendRadius);
+ double setBendRadius = cp.BendRadius();
+ return(EQUAL(bendRadius, setBendRadius));
+}
+
+bool testControlPointSetPointMethod()
+{
+ Pipe p = Pipe();
+ Pipe::ControlPoint cp;
+ Vector3D point = Vector3D(1.0, 1.0, 1.0);
+ double innerDiameter = 3.0;
+ double outerDiameter = 6.0;
+ double bendRadius = 4.0; /* bendRadius > outerDiameter / 2 */
+ cp = p.AppendControlPoint(point, innerDiameter, outerDiameter, bendRadius);
+ point = Vector3D(10.0, 10.0, 5.0);
+ innerDiameter = 3.0;
+ outerDiameter = 6.0;
+ bendRadius = 5.0; /* bendRadius > outerDiameter / 2 */
+ cp = p.AppendControlPoint(point, innerDiameter, outerDiameter, bendRadius);
+ cp = p.Get(1);
+ cp.SetPoint(point);
+ const Vector3D setPoint = cp.Point();
+ return(VECTOR3D_EQUAL(point, setPoint));
+}
+
+bool testControlPointSetInnerDiameterMethod()
+{
+ Pipe p = Pipe();
+ Pipe::ControlPoint cp;
+ Vector3D point = Vector3D(1.0, 1.0, 1.0);
+ double innerDiameter = 3.0;
+ double outerDiameter = 6.0;
+ double bendRadius = 4.0; /* bendRadius > outerDiameter / 2 */
+ cp = p.AppendControlPoint(point, innerDiameter, outerDiameter, bendRadius);
+ point = Vector3D(10.0, 10.0, 5.0);
+ innerDiameter = 3.0;
+ outerDiameter = 6.0;
+ bendRadius = 5.0; /* bendRadius > outerDiameter / 2 */
+ cp = p.AppendControlPoint(point, innerDiameter, outerDiameter, bendRadius);
+ cp = p.Get(0);
+ cp.SetInnerDiameter(innerDiameter);
+ double setInnerDiameter = cp.InnerDiameter();
+ return(EQUAL(innerDiameter, setInnerDiameter));
+}
+
+bool testControlPointSetOuterDiameterMethod()
+{
+ Pipe p = Pipe();
+ Pipe::ControlPoint cp;
+ Vector3D point = Vector3D(1.0, 1.0, 1.0);
+ double innerDiameter = 3.0;
+ double outerDiameter = 6.0;
+ double bendRadius = 4.0; /* bendRadius > outerDiameter / 2 */
+ cp = p.AppendControlPoint(point, innerDiameter, outerDiameter, bendRadius);
+ point = Vector3D(10.0, 10.0, 5.0);
+ innerDiameter = 3.0;
+ outerDiameter = 6.0;
+ bendRadius = 5.0; /* bendRadius > outerDiameter / 2 */
+ cp = p.AppendControlPoint(point, innerDiameter, outerDiameter, bendRadius);
+ cp = p.Get(0);
+ cp.SetOuterDiameter(outerDiameter);
+ double setOuterDiameter = cp.OuterDiameter();
+ return(EQUAL(outerDiameter, setOuterDiameter));
+}
+
+bool testControlPointSetBendRadiusMethod()
+{
+ Pipe p = Pipe();
+ Pipe::ControlPoint cp;
+ Vector3D point = Vector3D(1.0, 1.0, 1.0);
+ double innerDiameter = 3.0;
+ double outerDiameter = 6.0;
+ double bendRadius = 4.0; /* bendRadius > outerDiameter / 2 */
+ cp = p.AppendControlPoint(point, innerDiameter, outerDiameter, bendRadius);
+ point = Vector3D(10.0, 10.0, 5.0);
+ innerDiameter = 3.0;
+ outerDiameter = 6.0;
+ bendRadius = 5.0; /* bendRadius > outerDiameter / 2 */
+ cp = p.AppendControlPoint(point, innerDiameter, outerDiameter, bendRadius);
+ cp = p.Get(1);
+ cp.SetBendRadius(bendRadius);
+ double setBendRadius = cp.BendRadius();
+ return(EQUAL(bendRadius, setBendRadius));
+}
+
+bool testPipeDeleteControlPointMethod()
+{
+ Pipe p1 = makePipe();
+ Pipe p2 = makePipe();
+ Pipe::ControlPoint cp1;
+ Pipe::ControlPoint cp2;
+ p1.DeleteControlPoint(0);
+ cp1 = p1.Get(0);
+ cp2 = p2.Get(0);
+ const Vector3D point1 = cp1.Point();
+ const Vector3D point2 = cp2.Point();
+ const double innerDiameter1 = cp1.InnerDiameter();
+ const double innerDiameter2 = cp2.InnerDiameter();
+ const double outerDiameter1 = cp1.OuterDiameter();
+ const double outerDiameter2 = cp2.OuterDiameter();
+ const double bendRadius1 = cp1.BendRadius();
+ const double bendRadius2 = cp2.BendRadius();
+ return(!(VECTOR3D_EQUAL(point1, point2) &&
+ EQUAL(innerDiameter1, innerDiameter2) &&
+ EQUAL(outerDiameter1, outerDiameter2) &&
+ EQUAL(bendRadius1, bendRadius2)));
+}
+
+bool testPipeCloneMethod()
+{
+ Pipe p = makePipe();
+ Pipe *clonedPipe = static_cast<Pipe *>(p.Clone());
+ return clonedPipe->IsValid();
+}
+
+void test_pipe(Database& database)
+{
+ Pipe p = makePipe();
+ bool allPipeTestsPassed = true;
+
+ /* Run tests */
+ if(p.IsValid()) {
+ std::cout << "Starting Pipe unit testing . . ." << std::endl;
+ ADD_TEST(testPipeInsertControlPointMethod(), allPipeTestsPassed);
+ ADD_TEST(testPipeAppendControlPointMethod(), allPipeTestsPassed);
+ ADD_TEST(testPipeGetControlPointMethod(), allPipeTestsPassed);
+ ADD_TEST(testControlPointGetPointMethod(), allPipeTestsPassed);
+ ADD_TEST(testControlPointGetInnerDiameterMethod(), allPipeTestsPassed);
+ ADD_TEST(testControlPointGetOuterDiameterMethod(), allPipeTestsPassed);
+ ADD_TEST(testControlPointGetBendRadius(), allPipeTestsPassed);
+ ADD_TEST(testControlPointSetPointMethod(), allPipeTestsPassed);
+ ADD_TEST(testControlPointSetInnerDiameterMethod(), allPipeTestsPassed);
+ ADD_TEST(testControlPointSetOuterDiameterMethod(), allPipeTestsPassed);
+ ADD_TEST(testControlPointSetBendRadiusMethod(), allPipeTestsPassed);
+ ADD_TEST(testPipeDeleteControlPointMethod(), allPipeTestsPassed);
+ ADD_TEST(testPipeCloneMethod(), allPipeTestsPassed);
+ } else {
+ std::cout << "Default Pipe is not valid" << std::endl;
+ allPipeTestsPassed = false;
+ }
+
+ /* We only add the pipe to the database if it failed no tests */
+ if(allPipeTestsPassed) {
+ std::cout << "All Pipe tests passed, adding object to database . . . "
<< std::endl;
+ database.Add(p);
+ }
+}
+
+
+/*
+ * Local Variables:
+ * mode: C++
+ * tab-width: 8
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: rt^3/trunk/tests/coreInterface/pipe.cpp
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: rt^3/trunk/tests/coreInterface/primitives.cpp
===================================================================
--- rt^3/trunk/tests/coreInterface/primitives.cpp 2015-08-09 22:29:30 UTC
(rev 65862)
+++ rt^3/trunk/tests/coreInterface/primitives.cpp 2015-08-10 14:01:31 UTC
(rev 65863)
@@ -1,4 +1,4 @@
- /* P R I M I T I V E S . C P P
+/* P R I M I T I V E S . C P P
* BRL-CAD
*
* Copyright (c) 2014 United States Government as represented by
@@ -47,6 +47,10 @@
if (database.Load(argv[1])) {
test_halfspace(database);
+ test_ellipsoid(database);
+ test_sphere(database);
+ test_cone(database);
+ test_pipe(database);
} else {
std::cout << "Could not load file: " << argv[1] << std::endl;
ret = 2;
@@ -64,8 +68,9 @@
/*
* Local Variables:
- * mode: C
+ * mode: C++
* tab-width: 8
+ * c-basic-offset: 4
* indent-tabs-mode: t
* c-file-style: "stroustrup"
* End:
Modified: rt^3/trunk/tests/coreInterface/primitives.h
===================================================================
--- rt^3/trunk/tests/coreInterface/primitives.h 2015-08-09 22:29:30 UTC (rev
65862)
+++ rt^3/trunk/tests/coreInterface/primitives.h 2015-08-10 14:01:31 UTC (rev
65863)
@@ -29,7 +29,11 @@
#include "brlcad/Database.h"
+void test_cone(BRLCAD::Database& database);
+void test_ellipsoid(BRLCAD::Database& database);
void test_halfspace(BRLCAD::Database& database);
+void test_pipe(BRLCAD::Database& database);
+void test_sphere(BRLCAD::Database& database);
#endif // PRIMITIVES_H
@@ -37,8 +41,9 @@
/*
* Local Variables:
- * mode: C
+ * mode: C++
* tab-width: 8
+ * c-basic-offset: 4
* indent-tabs-mode: t
* c-file-style: "stroustrup"
* End:
Added: rt^3/trunk/tests/coreInterface/sphere.cpp
===================================================================
--- rt^3/trunk/tests/coreInterface/sphere.cpp (rev 0)
+++ rt^3/trunk/tests/coreInterface/sphere.cpp 2015-08-10 14:01:31 UTC (rev
65863)
@@ -0,0 +1,207 @@
+/* S P H E R E . C P P
+ * BRL-CAD
+ *
+ * Copyright (c) 2015 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 file; see the file named COPYING for more
+ * information.
+ */
+/** @file Sphere.cpp
+ *
+ * C++ core interface Sphere test
+ *
+ */
+
+#include <iostream>
+#include <string>
+#include <brlcad/Sphere.h>
+#include "primitives.h"
+#include "bn.h"
+
+using namespace BRLCAD;
+
+#define ADD_TEST(expression, allTestsPassed) \
+ if (!expression) { \
+ std::cout << "Failed test: " << #expression << std::endl; \
+ allTestsPassed = false; \
+ } else { \
+ std::cout << "Passed test: " << #expression << std::endl; \
+ }
+
+/* Tests Sphere's Center function */
+bool testSphereCenter(const BRLCAD::Sphere &sphere,
+ const double expectedX,
+ const double expectedY,
+ const double expectedZ)
+{
+ const BRLCAD::Vector3D center = sphere.Center();
+ return(EQUAL(center.coordinates[0], expectedX) &&
+ EQUAL(center.coordinates[1], expectedY) &&
+ EQUAL(center.coordinates[2], expectedZ));
+}
+
+/* Tests Sphere's ClassName function */
+bool testSphereClassName(const BRLCAD::Sphere &sphere)
+{
+ const std::string name = "Sphere";
+ const std::string actualName = sphere.ClassName();
+ return(actualName.compare(name) == 0);
+}
+
+/* Tests Sphere's Type function */
+bool testSphereType(const BRLCAD::Sphere &sphere)
+{
+ return(sphere.Type() == sphere.ClassName());
+}
+
+/* Tests Sphere's IsValid function */
+bool testSphereIsValid(const BRLCAD::Sphere &sphere)
+{
+ return(sphere.IsValid());
+}
+
+/* Tests Sphere's SphereRadius function */
+bool testSphereRadius(const BRLCAD::Sphere &sphere, const double
expectedRadius)
+{
+ return(EQUAL(sphere.Radius(), expectedRadius));
+}
+
+/* Tests Sphere's Clone function */
+bool testSphereClone(BRLCAD::Sphere sphere)
+{
+ BRLCAD::Sphere sphere2;
+ sphere2 = *static_cast<BRLCAD::Sphere*>(sphere.Clone());
+ const BRLCAD::Vector3D center = sphere.Center();
+ const BRLCAD::Vector3D center2 = sphere2.Center();
+ return(EQUAL(center2.coordinates[0], center.coordinates[0]) &&
+ EQUAL(center2.coordinates[1], center.coordinates[1]) &&
+ EQUAL(center2.coordinates[2], center.coordinates[2]) &&
+ EQUAL(sphere2.Radius(), sphere.Radius()));
+}
+
+/* Tests Sphere's Set function */
+bool testSphereSet()
+{
+ BRLCAD::Sphere sphere;
+ sphere.Set(Vector3D(1.0, 1.0, 1.0), 3.0);
+ return(EQUAL(sphere.Center().coordinates[0], 1.0) &&
+ EQUAL(sphere.Center().coordinates[1], 1.0) &&
+ EQUAL(sphere.Center().coordinates[0], 1.0) &&
+ EQUAL(sphere.Radius(), 3.0));
+}
+
+/* Tests Sphere's SetCenter function */
+bool testSphereSetCenter(const Vector3D &coords)
+{
+ BRLCAD::Sphere sphere;
+ sphere.SetCenter(coords);
+ const Vector3D center = sphere.Center();
+ return(EQUAL(center.coordinates[0], coords.coordinates[0]) &&
+ EQUAL(center.coordinates[1], coords.coordinates[1]) &&
+ EQUAL(center.coordinates[2], coords.coordinates[2]));
+}
+
+/* Tests Sphere's SetRadius function */
+bool testSphereSetRadius(const double expectedRadius)
+{
+ BRLCAD::Sphere sphere;
+ sphere.SetRadius(expectedRadius);
+ return(EQUAL(sphere.Radius(), expectedRadius));
+}
+
+/* Tests Sphere's Copy constructor */
+bool testSphereCopy(const BRLCAD::Sphere &sphere)
+{
+ BRLCAD::Sphere sphere2(sphere);
+ const Vector3D center = sphere.Center();
+ const Vector3D center2 = sphere2.Center();
+ return(sphere2.IsValid() &&
+ EQUAL(center2.coordinates[0], center.coordinates[0]) &&
+ EQUAL(center2.coordinates[1], center.coordinates[1]) &&
+ EQUAL(center2.coordinates[2], center.coordinates[2]) &&
+ EQUAL(sphere2.Radius(), sphere.Radius()));
+}
+
+/* Tests Sphere's default(unit) constructor */
+bool testUnitSphereConstructor()
+{
+ BRLCAD::Sphere sphere;
+ const Vector3D center = sphere.Center();
+ return(EQUAL(center.coordinates[0], 0.0) &&
+ EQUAL(center.coordinates[1], 0.0) &&
+ EQUAL(center.coordinates[2], 0.0) &&
+ EQUAL(sphere.Radius(), 1.0));
+}
+
+/* Tests Sphere's general constructor */
+bool testGeneralSphereConstructor(const Vector3D ¢er, const double radius)
+{
+ BRLCAD::Sphere sphere = BRLCAD::Sphere(center, radius);
+ const Vector3D newCenter = sphere.Center();
+ return(sphere.IsValid() &&
+ EQUAL(newCenter.coordinates[0], center.coordinates[0]) &&
+ EQUAL(newCenter.coordinates[1], center.coordinates[1]) &&
+ EQUAL(newCenter.coordinates[2], center.coordinates[2]) &&
+ EQUAL(sphere.Radius(), radius));
+}
+
+/* We now run all the tests */
+void test_sphere(BRLCAD::Database& database)
+{
+
+ /* Initialize a Sphere to test on */
+ BRLCAD::Sphere sphere;
+ const Vector3D center = Vector3D(1.0, 1.0, 1.0);
+ sphere.SetCenter(center);
+ sphere.SetRadius(3.0);
+
+ bool allSphereTestsPassed = true;
+
+ /* Runs all the tests */
+ if(testSphereIsValid(sphere)) {
+ std::cout << "Starting Sphere Unit testing . . ." << std::endl;
+ ADD_TEST(testSphereCenter(sphere, 1.0, 1.0, 1.0), allSphereTestsPassed);
+ ADD_TEST(testSphereRadius(sphere, 3.0), allSphereTestsPassed);
+ ADD_TEST(testSphereClassName(sphere), allSphereTestsPassed);
+ ADD_TEST(testSphereType(sphere), allSphereTestsPassed);
+ ADD_TEST(testSphereSet(), allSphereTestsPassed);
+ ADD_TEST(testSphereSetCenter(center), allSphereTestsPassed);
+ ADD_TEST(testSphereSetRadius(3.0), allSphereTestsPassed);
+ ADD_TEST(testSphereClone(sphere), allSphereTestsPassed);
+ ADD_TEST(testSphereCopy(sphere), allSphereTestsPassed);
+ ADD_TEST(testUnitSphereConstructor(), allSphereTestsPassed);
+ ADD_TEST(testGeneralSphereConstructor(sphere.Center(),
sphere.Radius()), allSphereTestsPassed);
+ } else {
+ std::cout << "Default Sphere is not valid" << std::endl;
+ allSphereTestsPassed = false;
+ }
+
+ /* We only add the sphere to the database if it failed no tests */
+ if(allSphereTestsPassed) {
+ std::cout << "All Sphere tests passed; adding object to database . . ."
<< std::endl;
+ database.Add(sphere);
+ }
+}
+
+
+/*
+ * Local Variables:
+ * mode: C++
+ * tab-width: 8
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: rt^3/trunk/tests/coreInterface/sphere.cpp
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: rt^3/trunk/tests/libge/CMakeLists.txt
===================================================================
--- rt^3/trunk/tests/libge/CMakeLists.txt 2015-08-09 22:29:30 UTC (rev
65862)
+++ rt^3/trunk/tests/libge/CMakeLists.txt 2015-08-10 14:01:31 UTC (rev
65863)
@@ -34,7 +34,7 @@
include_directories (
${BRLCAD_INCLUDE_DIRS}
- ${TCL_INCLUDE_PATH}
+ ${TCL_INCLUDE_PATH}
)
set (geTest_SRC
@@ -43,4 +43,3 @@
add_executable(geTest ${geTest_SRC} )
target_link_libraries(geTest coreinterface ge)
-
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits