Skip to content

Commit

Permalink
Merge pull request #807 from copyme/3Display-cleaning
Browse files Browse the repository at this point in the history
Public method which allows to clean 3Display
  • Loading branch information
dcoeurjo committed May 7, 2014
2 parents 9021574 + 6b8713d commit 49c4c1e
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/DGtal/io/Display3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,12 @@ namespace DGtal
bool isValid() const;


/**
* Removes all sent data.
*/
void clear();



/**
* Use to embed a DGtal point into space
Expand Down
23 changes: 22 additions & 1 deletion src/DGtal/io/Display3D.ih
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,28 @@ DGtal::Display3D< Space ,KSpace >::normalize (double vec[3])
vec[2] /= sqrt (squaredLen);
}


template < typename Space ,typename KSpace >
inline
void
DGtal::Display3D< Space ,KSpace >::clear()
{
myCubeSetList.clear();
myLineSetList.clear();
myBallSetList.clear();
myClippingPlaneList.clear();
myPrismList.clear();
myQuadSetList.clear();
myTriangleSetList.clear();
myPolygonSetList.clear();
myCubeSetNameList.clear();
myLineSetNameList.clear();
myBallSetNameList.clear();
myClippingPlaneNameList.clear();
myPrismNameList.clear();
myQuadSetNameList.clear();
myTriangleSetNameList.clear();
myPolygonSetNameList.clear();
}



Expand Down
1 change: 1 addition & 0 deletions tests/io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_subdirectory(viewers)
add_subdirectory(colormaps)
add_subdirectory(readers)
add_subdirectory(writers)
add_subdirectory(boards)



13 changes: 13 additions & 0 deletions tests/io/boards/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

SET(DGTAL_TESTS_SRC_BOARDS
testBoard3d
)

FOREACH(FILE ${DGTAL_TESTS_SRC_BOARDS})
add_executable(${FILE} ${FILE})
target_link_libraries (${FILE} DGtalIO DGtal ${DGtalLibDependencies})
ENDFOREACH(FILE)




119 changes: 119 additions & 0 deletions tests/io/boards/testBoard3d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
* 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 3 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
**/

/**
* @file testBoard3d.cpp
* @ingroup Tests
* @author Kacper Pluta (\c [email protected] )
*
* @date 2014/05/03
*
* Functions for testing class Board3D.
*
* This file is part of the DGtal library.
*/

///////////////////////////////////////////////////////////////////////////////


#include <iostream>
#include "DGtal/io/boards/Board3D.h"
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/io/DrawWithDisplay3DModifier.h"

///////////////////////////////////////////////////////////////////////////////

using namespace std;
using namespace DGtal;
using namespace Z3i;

///////////////////////////////////////////////////////////////////////////////

bool testClearBoard3d()
{
unsigned int nbok = 0;
unsigned int nb = 4;

KSpace K;
Point plow(0,0,0);
Point pup(20,20,20);
Domain domain( plow, pup );
K.init( plow, pup, true );
Board3D<Space, KSpace> board(K);

trace.beginBlock("Testing Board3D: SCells");
SCell v = K.sSpel( Point( 0, 0, 0 ), KSpace::POS );
SCell v2 = K.sSpel( Point( 1, 0, 0 ), KSpace::POS );
SCell v3 = K.sSpel( Point( 0, 1, 0 ), KSpace::POS );

board << v << v2 << v3;
board.saveOBJ("board3d-cells.obj");
board.clear();
trace.info() << "File written as \"board3d-cells.obj\". All sent SCels were removed." << std::endl;
nbok++;
trace.endBlock();

trace.beginBlock("Testing Board3D: 3D points");
Point p1( -3, -2, 0 );
Point p2( 7, 3 , 6);
Point p3( -1, -1, -1);

board << p1 << p2 << p3;
board.saveOBJ("board3D-points.obj");
board.clear();
trace.info() << "File written as \"board3D-points.obj\". All sent points were removed." << std::endl;
nbok++;
trace.endBlock();

trace.beginBlock("Testing Board3D: Ball and clipping palnes");
DigitalSet shape_set(domain);
Shapes<Domain>::addNorm2Ball( shape_set, Point( 10, 10, 10 ), 7 );
board << SetMode3D( shape_set.className(), "Both" );
board << shape_set;
board << CustomColors3D(Color(250, 200,0, 100),Color(250, 200,0, 20));
board << SetMode3D( p1.className(), "Paving" );
board << ClippingPlane(1,0,0,-4.9);
board << ClippingPlane(0,1,0.3,-10);

board.saveOBJ("board3d-clipped-ball.obj");
board.clear();
trace.info() << "File written as \"board3d-clipped-ball.obj\". All sent clipping palnes and ball were removed." << std::endl;
nbok++;
trace.endBlock();

trace.beginBlock("Testing Board3D: Empty file.");
board.saveOBJ("null.obj");
trace.info() << "File written as \"null.obj\"." << std::endl;
nbok++;
trace.endBlock();

return nbok == nb;
}

///////////////////////////////////////////////////////////////////////////////

int main(int, char**)
{

trace.beginBlock ( "Testing class Board3D" );
trace.info() << "Testing Display3D::clear()" << std::endl;
bool res = testClearBoard3d();
trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
trace.endBlock();
return res ? 0 : 1;
}

0 comments on commit 49c4c1e

Please sign in to comment.