API Documentation
Loading...
Searching...
No Matches
GridFactory.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: IOFactory
28File: GridFactory
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/FactoryOptions.h>
34#if NDEVR_GRID
35#include <NDEVR/Grid.h>
36#include <NDEVR/Geometry.h>
37#include <NDEVR/Model.h>
38#include <NDEVR/Grid.h>
39#include <NDEVR/Material.h>
40
41#include <NDEVR/Scanner.h>
42#include <NDEVR/Translator.h>
43#include <NDEVR/Exception.h>
44
45namespace NDEVR
46{
47 class GridFactory
48 {
49 public:
50 static void readFile(File& file, Model& model, const FactoryOptions&)
51 {
52 Scanner scanner(file);
53
54
55 Vector<2, fltp08> offset;
56 Vector<2, fltp08> size;
57 Vector<2, uint04> index_size;
58 Geometry mesh = model.createChildGeometry();
59 Grid grid_mesh(mesh);
60 scanner.nextLine(); offset[Y] = scanner.getNext<fltp08>();
61 scanner.nextLine(); offset[X] = scanner.getNext<fltp08>();
62 scanner.nextLine(); size[Y] = scanner.getNext<fltp08>() - offset[Y];
63 scanner.nextLine(); size[X] = scanner.getNext<fltp08>() - offset[X];
64
65
66 scanner.nextLine(); index_size[X] = scanner.getNext<uint04>() + 1;
67 scanner.nextLine(); index_size[Y] = scanner.getNext<uint04>() + 1;
68
69 Vector<2, fltp08> scale = size / (index_size - 1U).as<2, fltp08>();
70
71 grid_mesh.setupVertexTable(index_size, Geometry::e_cartesian_1F);
72
73 for (uint04 y = 0; y < index_size[Y]; y++)
74 {
75 for (uint04 x = 0; x < index_size[X]; x++)
76 {
77 if (!scanner.nextLine())
78 throw FileException(String(file), _t("Bad vertex size"));
79 grid_mesh.setGridVector(VertexProperty::Position, x, y, scanner.getNext<fltp04>());
80 }
81 }
82 Matrix<fltp08> trans(1);
83 trans = trans.offset(offset);
84 trans = trans.scale(scale);
85 mesh.setTransform(trans);
86
87 grid_mesh.calculateGridNormals();
88
89 Material mat = model.createChildMaterial(PrimitiveProperty::Solid);
90 mat.setShadingModel(Material::ShadingModel::e_phong);
91
92 mat.setUVMode(UVType::e_KD, Material::UVMode::e_solid_color);
93 mat.setUVColor(UVType::e_KD, Vector<4, fltp04>(.5f, .5f, .5f, 1.0f));
94
95 mat.setUVMode(UVType::e_KS, Material::UVMode::e_solid_color);
96 mat.setUVColor(UVType::e_KS, Vector<4, fltp04>(.1f, .1f, .1f, 1.0f));
97 }
98 static bool canRead(const File& file)
99 {
100 if (file.endsWith(".grd", true))
101 return true;
102 return false;
103 }
104 };
105
106}
107#endif
108
#define _t(english_string)
Definition Translator.h:90
Definition ACIColor.h:37
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:115
QAction * mesh(nullptr)
@ Y
Definition BaseValues.hpp:197
@ X
Definition BaseValues.hpp:195
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:176