iMSTK
Interactive Medical Simulation Toolkit
Box.cpp
1 /*=========================================================================
2 
3  Library: iMSTK
4 
5  Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
6  & Imaging in Medicine, Rensselaer Polytechnic Institute.
7 
8  Licensed under the Apache License, Version 2.0 (the "License",
9  you may not use this file except in compliance with the License.
10  You may obtain a copy of the License at
11 
12  http://www.apache.org/licenses/LICENSE-2.0.txt
13 
14  Unless required by applicable law or agreed to in writing, software
15  distributed under the License is distributed on an "AS IS" BASIS,
16  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  See the License for the specific language governing permissions and
18  limitations under the License.
19 
20 =========================================================================*/
21 
22 #include "imstkMath.h"
23 #include "imstkVecDataArray.h"
24 
25 using namespace imstk;
26 
27 std::pair<std::shared_ptr<VecDataArray<double, 3>>, std::shared_ptr<VecDataArray<int, 3>>>
28 getBox()
29 {
30  std::vector<double> buffVertices
31  {
32  0.353553385, -0.707106769, -0.353553414,
33  -0.353553414, -0.707106769, 0.353553385,
34  0.853553414, 0, 0.146446615,
35  0.146446615, 0, 0.853553414,
36  -0.853553414, 0, -0.146446615,
37  -0.146446615, 0, -0.853553414,
38  -0.353553385, 0.707106769, 0.353553414,
39  0.353553414, 0.707106769, -0.353553385
40  };
41 
42  std::vector<int> buffFaces
43  {
44  1, 4, 2,
45  1, 3, 4,
46  5, 8, 6,
47  5, 7, 8,
48  7, 3, 8,
49  7, 4, 3,
50  6, 2, 5,
51  6, 1, 2,
52  6, 3, 1,
53  6, 8, 3,
54  2, 7, 5,
55  2, 4, 7
56  };
57 
58  std::shared_ptr<VecDataArray<double, 3>> verticesPtr = std::make_shared<VecDataArray<double, 3>>();
59  VecDataArray<double, 3>& vertices = *verticesPtr;
60  vertices.reserve(static_cast<int>(buffVertices.size() / 3));
61  for (size_t i = 0; i < buffVertices.size() / 3; ++i)
62  {
63  vertices.push_back(Vec3d(buffVertices[i * 3],
64  buffVertices[i * 3 + 1],
65  buffVertices[i * 3 + 2]));
66  }
67 
68  std::shared_ptr<VecDataArray<int, 3>> facesPtr = std::make_shared<VecDataArray<int, 3>>();
69  VecDataArray<int, 3>& faces = *facesPtr;
70  faces.reserve(static_cast<int>(buffFaces.size() / 3));
71  for (size_t i = 0; i < buffFaces.size() / 3; ++i)
72  {
73  // Face ID of triangles is 0-based index (data from .obj file is 1-based index)
74  faces.push_back(Vec3i(buffFaces[i * 3] - 1, buffFaces[i * 3 + 1] - 1, buffFaces[i * 3 + 2] - 1));
75  }
76 
77  return { verticesPtr, facesPtr };
78 }
Compound Geometry.
void reserve(const int size) override
Allocates extra capacity, for the number of values, conservative reallocate.