OpenWalnut  1.5.0dev
WManipulatorNormalize.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2017 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <memory>
26 
27 #include "WManipulatorNormalize.h"
28 #include "core/dataHandler/WDataSetSingle.h"
29 
30 WManipulatorNormalize::WManipulatorNormalize( std::shared_ptr< WDataSet >* dataSet )
31  : WObjectNDIP< WManipulatorInterface >( "Normalize", "Scales the dataset to form a unit cube." ),
32  m_dataSet( dataSet )
33 {
34  m_normalize = m_properties->addProperty( "Scale", "Scale of the data.", WPosition( 1.0, 1.0, 1.0 ) );
35 }
36 
38 {
39 }
40 
42 {
44 
45  WDataSetSingle::SPtr dsSingle = std::dynamic_pointer_cast< WDataSetSingle >( *m_dataSet );
46  if( !dsSingle )
47  {
48  return m;
49  }
50 
51  WBoundingBox bbox;
52 
53  // Is this a data set with a regular grid?
54  WGridRegular3D::SPtr regGrid;
55  regGrid = std::dynamic_pointer_cast< WGridRegular3D >( dsSingle->getGrid() );
56  if( !regGrid )
57  {
58  return m;
59  }
60  else
61  {
62  bbox = regGrid->getBoundingBox();
63  }
64 
65  for( size_t id = 0; id < 3; ++id )
66  {
67  double distance = bbox.getMax()[id] - bbox.getMin()[id];
68  if( distance > 0.0 )
69  {
70  m( id, id ) = 1.0 / ( distance );
71  }
72  }
73  m_normalize->set( WPosition( m( 0, 0 ), m( 1, 1 ), m( 2, 2 ) ) );
74 
75  return m;
76 }
77 
79 {
80  return m_normalize->changed();
81 }
82 
84 {
85  m_normalize->set( WPosition( 1.0, 1.0, 1.0 ) );
86 }
const vec_type & getMax() const
Gives the back upper right aka maximum corner.
Definition: WBoundingBox.h:308
const vec_type & getMin() const
Gives the front lower left aka minimum corner.
Definition: WBoundingBox.h:302
std::shared_ptr< WDataSetSingle > SPtr
Convenience typedef for a std::shared_ptr.
std::shared_ptr< WGridRegular3DTemplate > SPtr
Convenience typedef for a std::shared_ptr< WGridRegular3DTemplate >.
An interface for dataset transformation manipulators.
WPropPosition m_normalize
The normalize parameters as a vector.
virtual void reset()
Reset the transform.
WManipulatorNormalize(std::shared_ptr< WDataSet > *dataSet)
Constructor.
virtual ~WManipulatorNormalize()
Destructor.
virtual bool transformationChanged() const
Check if the transform has changed, for example because of a change to properties.
virtual WMatrixFixed< double, 4, 4 > getTransformationMatrix() const
Get the transformation matrix from this manipulator.
std::shared_ptr< WDataSet > * m_dataSet
Pointer to the dataset to be normalized.
static MatrixType identity()
Returns an identity matrix.
Definition: WMatrixFixed.h:310
This is a base class for everything which has a Name,Description,Icon and Properties (=NDIP).
Definition: WObjectNDIP.h:42
WProperties::SPtr m_properties
the properties of the object.
Definition: WObjectNDIP.h:99
This only is a 3d double vector.