Commit 66b7e4f4 authored by Matt Clarkson's avatar Matt Clarkson

Issue #66: Modify LoadModel3D to work with and without a newline at end of file.

parent 8b05a744
......@@ -18,6 +18,7 @@
#include <iostream>
#include <fstream>
#include <sstream>
namespace niftk {
......@@ -126,19 +127,28 @@ Model3D LoadModel3D(const std::string& fileName)
Model3D result;
while (ifs.good())
std::string line;
while (std::getline(ifs, line))
{
std::stringstream ss;
ss << line;
Point3D tmp;
ifs >> tmp.id;
ifs >> tmp.point.x;
ifs >> tmp.point.y;
ifs >> tmp.point.z;
if (ifs.good())
ss >> tmp.id;
ss >> tmp.point.x;
ss >> tmp.point.y;
ss >> tmp.point.z;
if (!ifs.bad() && !ifs.fail())
{
result.insert(IdPoint3D(tmp.id, tmp));
}
}
if (ifs.bad())
{
niftkNiftyCalThrow() << "Failed to read file:" << fileName << std::endl;
}
ifs.close();
return result;
......
......@@ -19,6 +19,7 @@ set(TEST_CASES
niftkNiftyCalExceptionTest
niftkPointUtilitiesTest
niftkPointDistortionTest
niftkLoadModelTest
niftkMatrixAverageTest
niftkStereoMatrixIOTest
niftkWarpChessboardByHomographyTest
......@@ -66,6 +67,8 @@ endforeach()
# Put unit-tests at the top. There is no point trying to assess the correctness of functional
# requirements, if the internal and most lowest level unit tests themselves do not work.
add_test(UNIT-NiftyCalExcept ${EXECUTABLE_OUTPUT_PATH}/niftkNiftyCalExceptionTest)
add_test(UNIT-LoadModelNewline ${EXECUTABLE_OUTPUT_PATH}/niftkLoadModelTest ${DATA_DIR}/Laparoscope/chessboard_13_10_3.txt 130)
add_test(UNIT-LoadModelNoNewline ${EXECUTABLE_OUTPUT_PATH}/niftkLoadModelTest ${DATA_DIR}/Laparoscope/chessboard_13_10_3_no_newline_at_end.txt 130)
add_test(UNIT-PointUtils ${EXECUTABLE_OUTPUT_PATH}/niftkPointUtilitiesTest)
add_test(UNIT-PointDist ${EXECUTABLE_OUTPUT_PATH}/niftkPointDistortionTest ${DATA_DIR}/Laparoscope/calib.left.intrinsic.txt ${DATA_DIR}/Laparoscope/calib.left.distortion.txt 1920 1080 1098.3 267.087)
add_test(UNIT-InterpSurf1 ${EXECUTABLE_OUTPUT_PATH}/niftkInterpolateQuadraticSurfaceTest)
......
0 0 0 0
1 3 0 0
2 6 0 0
3 9 0 0
4 12 0 0
5 15 0 0
6 18 0 0
7 21 0 0
8 24 0 0
9 27 0 0
10 30 0 0
11 33 0 0
12 36 0 0
13 0 3 0
14 3 3 0
15 6 3 0
16 9 3 0
17 12 3 0
18 15 3 0
19 18 3 0
20 21 3 0
21 24 3 0
22 27 3 0
23 30 3 0
24 33 3 0
25 36 3 0
26 0 6 0
27 3 6 0
28 6 6 0
29 9 6 0
30 12 6 0
31 15 6 0
32 18 6 0
33 21 6 0
34 24 6 0
35 27 6 0
36 30 6 0
37 33 6 0
38 36 6 0
39 0 9 0
40 3 9 0
41 6 9 0
42 9 9 0
43 12 9 0
44 15 9 0
45 18 9 0
46 21 9 0
47 24 9 0
48 27 9 0
49 30 9 0
50 33 9 0
51 36 9 0
52 0 12 0
53 3 12 0
54 6 12 0
55 9 12 0
56 12 12 0
57 15 12 0
58 18 12 0
59 21 12 0
60 24 12 0
61 27 12 0
62 30 12 0
63 33 12 0
64 36 12 0
65 0 15 0
66 3 15 0
67 6 15 0
68 9 15 0
69 12 15 0
70 15 15 0
71 18 15 0
72 21 15 0
73 24 15 0
74 27 15 0
75 30 15 0
76 33 15 0
77 36 15 0
78 0 18 0
79 3 18 0
80 6 18 0
81 9 18 0
82 12 18 0
83 15 18 0
84 18 18 0
85 21 18 0
86 24 18 0
87 27 18 0
88 30 18 0
89 33 18 0
90 36 18 0
91 0 21 0
92 3 21 0
93 6 21 0
94 9 21 0
95 12 21 0
96 15 21 0
97 18 21 0
98 21 21 0
99 24 21 0
100 27 21 0
101 30 21 0
102 33 21 0
103 36 21 0
104 0 24 0
105 3 24 0
106 6 24 0
107 9 24 0
108 12 24 0
109 15 24 0
110 18 24 0
111 21 24 0
112 24 24 0
113 27 24 0
114 30 24 0
115 33 24 0
116 36 24 0
117 0 27 0
118 3 27 0
119 6 27 0
120 9 27 0
121 12 27 0
122 15 27 0
123 18 27 0
124 21 27 0
125 24 27 0
126 27 27 0
127 30 27 0
128 33 27 0
129 36 27 0
\ No newline at end of file
/*=============================================================================
NiftyCal: A software package for camera calibration.
Copyright (c) University College London (UCL). All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
See LICENSE.txt in the top level directory for details.
=============================================================================*/
#include "catch.hpp"
#include "niftkCatchMain.h"
#include "niftkNiftyCalTypes.h"
#include "niftkIOUtilities.h"
TEST_CASE( "Load 3D Model, check against expected number of points", "[IO]" ) {
int expectedNumberOfArguments = 3;
if (niftk::argc != expectedNumberOfArguments)
{
std::cerr << "Usage: niftkLoadModelTest model.txt expectedNumberOfPoints" << std::endl;
REQUIRE( niftk::argc == expectedNumberOfArguments);
}
niftk::Model3D model = niftk::LoadModel3D(niftk::argv[1]);
int expectedNumberOfPoints = atoi(niftk::argv[2]);
REQUIRE(model.size() == expectedNumberOfPoints);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment