ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ScaledIntegerNodeImpl.cpp
Go to the documentation of this file.
1 /*
2  * Original work Copyright 2009 - 2010 Kevin Ackley (kackley@gwi.net)
3  * Modified work Copyright 2018 - 2020 Andy Maloney <asmaloney@gmail.com>
4  *
5  * Permission is hereby granted, free of charge, to any person or organization
6  * obtaining a copy of the software and accompanying documentation covered by
7  * this license (the "Software") to use, reproduce, display, distribute,
8  * execute, and transmit the Software, and to prepare derivative works of the
9  * Software, and to permit third-parties to whom the Software is furnished to
10  * do so, all subject to the following:
11  *
12  * The copyright notices in the Software and this entire statement, including
13  * the above license grant, this restriction and the following disclaimer,
14  * must be included in all copies of the Software, in whole or in part, and
15  * all derivative works of the Software, unless such copies or derivative
16  * works are solely in the form of machine-executable object code generated by
17  * a source language processor.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  * DEALINGS IN THE SOFTWARE.
26  */
27 
28 #include <cmath>
29 
30 #include "CheckedFile.h"
31 #include "ScaledIntegerNodeImpl.h"
32 
33 namespace e57
34 {
35  ScaledIntegerNodeImpl::ScaledIntegerNodeImpl( ImageFileImplWeakPtr destImageFile, int64_t rawValue, int64_t minimum,
36  int64_t maximum, double scale, double offset ) :
37  NodeImpl( destImageFile ), value_( rawValue ), minimum_( minimum ), maximum_( maximum ), scale_( scale ),
38  offset_( offset )
39  {
40  // don't checkImageFileOpen, NodeImpl() will do it
41 
43  if ( rawValue < minimum || maximum < rawValue )
44  {
46  "this->pathName=" + this->pathName() + " rawValue=" + toString( rawValue ) +
47  " minimum=" + toString( minimum ) + " maximum=" + toString( maximum ) );
48  }
49  }
50 
52  double scaledMinimum, double scaledMaximum, double scale,
53  double offset ) :
54  NodeImpl( destImageFile ), value_( static_cast<int64_t>( std::floor( ( scaledValue - offset ) / scale + .5 ) ) ),
55  minimum_( static_cast<int64_t>( std::floor( ( scaledMinimum - offset ) / scale + .5 ) ) ),
56  maximum_( static_cast<int64_t>( std::floor( ( scaledMaximum - offset ) / scale + .5 ) ) ), scale_( scale ),
57  offset_( offset )
58  {
59  // don't checkImageFileOpen, NodeImpl() will do it
60 
63  {
64  throw E57_EXCEPTION2( E57_ERROR_VALUE_OUT_OF_BOUNDS, "this->pathName=" + this->pathName() +
65  " scaledValue=" + toString( scaledValue ) +
66  " scaledMinimum=" + toString( scaledMinimum ) +
67  " scaledMaximum=" + toString( scaledMaximum ) );
68  }
69  }
70 
72  {
73  // don't checkImageFileOpen
74 
76  if ( ni->type() != E57_SCALED_INTEGER )
77  {
78  return ( false );
79  }
80 
82  std::shared_ptr<ScaledIntegerNodeImpl> ii( std::static_pointer_cast<ScaledIntegerNodeImpl>( ni ) );
83 
85  if ( minimum_ != ii->minimum_ )
86  {
87  return ( false );
88  }
89 
91  if ( maximum_ != ii->maximum_ )
92  {
93  return ( false );
94  }
95 
97  if ( scale_ != ii->scale_ )
98  {
99  return ( false );
100  }
101 
103  if ( offset_ != ii->offset_ )
104  {
105  return ( false );
106  }
107 
109 
111  return ( true );
112  }
113 
115  {
116  // don't checkImageFileOpen
117 
119  return pathName.empty();
120  }
121 
123  {
124  checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
125  return ( value_ );
126  }
127 
129  {
130  checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
131  return ( value_ * scale_ + offset_ );
132  }
133 
135  {
136  checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
137  return ( minimum_ );
138  }
140  {
141  checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
142  return ( minimum_ * scale_ + offset_ );
143  }
144 
146  {
147  checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
148  return ( maximum_ );
149  }
151  {
152  checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
153  return ( maximum_ * scale_ + offset_ );
154  }
155 
157  {
158  checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
159  return ( scale_ );
160  }
161 
163  {
164  checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
165  return ( offset_ );
166  }
167 
169  {
170  // don't checkImageFileOpen
171 
173  if ( pathNames.find( relativePathName( origin ) ) == pathNames.end() )
174  {
175  throw E57_EXCEPTION2( E57_ERROR_NO_BUFFER_FOR_ELEMENT, "this->pathName=" + this->pathName() );
176  }
177  }
178 
180  const char *forcedFieldName )
181  {
182  // don't checkImageFileOpen
183 
184  ustring fieldName;
185  if ( forcedFieldName != nullptr )
186  {
187  fieldName = forcedFieldName;
188  }
189  else
190  {
191  fieldName = elementName_;
192  }
193 
194  cf << space( indent ) << "<" << fieldName << " type=\"ScaledInteger\"";
195 
197  if ( minimum_ != E57_INT64_MIN )
198  {
199  cf << " minimum=\"" << minimum_ << "\"";
200  }
201  if ( maximum_ != E57_INT64_MAX )
202  {
203  cf << " maximum=\"" << maximum_ << "\"";
204  }
205  if ( scale_ != 1.0 )
206  {
207  cf << " scale=\"" << scale_ << "\"";
208  }
209  if ( offset_ != 0.0 )
210  {
211  cf << " offset=\"" << offset_ << "\"";
212  }
213 
215  if ( value_ != 0 )
216  {
217  cf << ">" << value_ << "</" << fieldName << ">\n";
218  }
219  else
220  {
221  cf << "/>\n";
222  }
223  }
224 
225 #ifdef E57_DEBUG
226  void ScaledIntegerNodeImpl::dump( int indent, std::ostream &os ) const
227  {
228  // don't checkImageFileOpen
229  os << space( indent ) << "type: ScaledInteger"
230  << " (" << type() << ")" << std::endl;
231  NodeImpl::dump( indent, os );
232  os << space( indent ) << "rawValue: " << value_ << std::endl;
233  os << space( indent ) << "minimum: " << minimum_ << std::endl;
234  os << space( indent ) << "maximum: " << maximum_ << std::endl;
235  os << space( indent ) << "scale: " << scale_ << std::endl;
236  os << space( indent ) << "offset: " << offset_ << std::endl;
237  }
238 #endif
239 }
int offset
int offset_
Definition: FilePLY.cpp:36
#define E57_EXCEPTION2(ecode, context)
Definition: Common.h:68
ustring elementName_
Definition: NodeImpl.h:96
ustring relativePathName(const NodeImplSharedPtr &origin, ustring childPathName=ustring()) const
Definition: NodeImpl.cpp:93
void checkImageFileOpen(const char *srcFileName, int srcLineNumber, const char *srcFunctionName) const
Definition: NodeImpl.cpp:41
virtual void dump(int indent=0, std::ostream &os=std::cout) const
Definition: NodeImpl.cpp:372
ustring pathName() const
Definition: NodeImpl.cpp:74
void checkLeavesInSet(const StringSet &pathNames, NodeImplSharedPtr origin) override
void dump(int indent=0, std::ostream &os=std::cout) const override
void writeXml(ImageFileImplSharedPtr imf, CheckedFile &cf, int indent, const char *forcedFieldName=nullptr) override
bool isDefined(const ustring &pathName) override
bool isTypeEquivalent(NodeImplSharedPtr ni) override
ScaledIntegerNodeImpl(ImageFileImplWeakPtr destImageFile, int64_t value=0, int64_t minimum=0, int64_t maximum=0, double scale=1.0, double offset=0.0)
NodeType type() const override
QTextStream & endl(QTextStream &stream)
Definition: QtCompat.h:718
MiniVec< float, N > floor(const MiniVec< float, N > &a)
Definition: MiniVec.h:75
std::shared_ptr< class NodeImpl > NodeImplSharedPtr
Definition: Common.h:190
std::weak_ptr< class ImageFileImpl > ImageFileImplWeakPtr
Definition: Common.h:189
std::shared_ptr< class ImageFileImpl > ImageFileImplSharedPtr
Definition: Common.h:188
@ E57_ERROR_VALUE_OUT_OF_BOUNDS
element value out of min/max bounds
Definition: E57Exception.h:81
@ E57_ERROR_NO_BUFFER_FOR_ELEMENT
Definition: E57Exception.h:69
std::string ustring
UTF-8 encodeded Unicode string.
Definition: E57Format.h:54
std::set< std::string > StringSet
Definition: Common.h:194
@ E57_SCALED_INTEGER
ScaledIntegerNode class.
Definition: E57Format.h:63
std::string toString(T x)
Definition: Common.h:80
std::string space(size_t n)
Definition: Common.h:73
Definition: Eigen.h:85