forked from ossimlabs/ossim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
239 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
//******************************************************************* | ||
// | ||
// License: MIT | ||
// | ||
// See LICENSE.txt file in the top level directory for more details. | ||
// | ||
// Description: Contains class definition for ossim2dTo2dCompositeTransform. | ||
// | ||
//******************************************************************* | ||
// $Id$ | ||
#ifndef ossim2dTo2dCompositeTransform_HEADER | ||
#define ossim2dTo2dCompositeTransform_HEADER | ||
#include <ossim/base/ossim2dTo2dTransform.h> | ||
#include <ossim/base/ossimRefPtr.h> | ||
#include <vector> | ||
|
||
/** | ||
* This is the identity transform and just passes the input to the output. | ||
*/ | ||
class OSSIM_DLL ossim2dTo2dCompositeTransform : public ossim2dTo2dTransform | ||
{ | ||
public: | ||
typedef std::vector<ossimRefPtr<ossim2dTo2dTransform> > CompositeTransformList; | ||
|
||
ossim2dTo2dCompositeTransform(const CompositeTransformList& compositeTransformList = CompositeTransformList()); | ||
ossim2dTo2dCompositeTransform(const ossim2dTo2dCompositeTransform& rhs); | ||
virtual ~ossim2dTo2dCompositeTransform(); | ||
virtual ossimObject* dup()const; | ||
|
||
|
||
void add(ossimRefPtr<ossim2dTo2dTransform> transform); | ||
void clear(); | ||
|
||
const CompositeTransformList& getCompositeTransformList()const; | ||
|
||
/** | ||
* Will iterate through the list of transforms from index 0 ... n -1 calling | ||
* the forward transform. The output of the previous is used as the input to the next | ||
* transform. | ||
*/ | ||
virtual void forward(const ossimDpt& input, | ||
ossimDpt& output) const; | ||
|
||
|
||
/** | ||
* will call the forward method with 2 arguments | ||
*/ | ||
virtual void forward(ossimDpt& /* modify_this */) const; | ||
|
||
/** | ||
* Will iterate through the transformation list in reverse order from | ||
* n-1 ... 0 calling the inverse for each one. The output is passed in as input | ||
* to the next transform. | ||
*/ | ||
virtual void inverse(const ossimDpt& input, | ||
ossimDpt& output) const; | ||
|
||
/** | ||
* will call the inverse method with 2 arguments | ||
*/ | ||
virtual void inverse(ossimDpt& /* modify_this */) const; | ||
|
||
/** | ||
* Pass equality to the parent | ||
*/ | ||
virtual const ossim2dTo2dCompositeTransform& operator=( | ||
const ossim2dTo2dCompositeTransform& rhs) | ||
{ | ||
ossim2dTo2dTransform::operator =(rhs); | ||
|
||
return *this; | ||
} | ||
|
||
/** | ||
* Saves the state of the composite by iterating through all transformas and saving | ||
* them to the keyword list with it's own prefix. | ||
* | ||
* values will be: | ||
* <prefix>.object0 | ||
* <prefix>.object1 | ||
* <prefix>.object<n-1> | ||
* | ||
*/ | ||
virtual bool saveState(ossimKeywordlist& kwl, const char* prefix=0)const; | ||
|
||
/** | ||
* Will laod the state of the object. Note, it will clear the list and then add | ||
* all prefix found from the save state. | ||
*/ | ||
virtual bool loadState(const ossimKeywordlist& kwl, const char* prefix=0); | ||
|
||
protected: | ||
/** | ||
* Holds the list of transforms. | ||
*/ | ||
CompositeTransformList m_compositeTransforms; | ||
|
||
TYPE_DATA | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#include <ossim/base/ossim2dTo2dCompositeTransform.h> | ||
#include <ossim/base/ossimKeywordlist.h> | ||
#include <ossim/base/ossim2dTo2dTransformRegistry.h> | ||
|
||
RTTI_DEF1_INST(ossim2dTo2dCompositeTransform, "ossim2dTo2dCompositeTransform", ossim2dTo2dTransform); | ||
|
||
ossim2dTo2dCompositeTransform::ossim2dTo2dCompositeTransform(const CompositeTransformList& compositeTransformList ) | ||
: m_compositeTransforms(compositeTransformList) | ||
{ | ||
|
||
} | ||
|
||
ossim2dTo2dCompositeTransform::ossim2dTo2dCompositeTransform(const ossim2dTo2dCompositeTransform& rhs) | ||
:m_compositeTransforms(rhs.m_compositeTransforms) | ||
{ | ||
|
||
} | ||
|
||
ossim2dTo2dCompositeTransform::~ossim2dTo2dCompositeTransform() | ||
{ | ||
clear(); | ||
} | ||
|
||
ossimObject* ossim2dTo2dCompositeTransform::dup()const | ||
{ | ||
return new ossim2dTo2dCompositeTransform(*this); | ||
} | ||
|
||
|
||
void ossim2dTo2dCompositeTransform::add(ossimRefPtr<ossim2dTo2dTransform> transform) | ||
{ | ||
if(transform) | ||
{ | ||
m_compositeTransforms.push_back(transform); | ||
} | ||
} | ||
|
||
void ossim2dTo2dCompositeTransform::clear() | ||
{ | ||
m_compositeTransforms.clear(); | ||
} | ||
|
||
const ossim2dTo2dCompositeTransform::CompositeTransformList& ossim2dTo2dCompositeTransform::getCompositeTransformList()const | ||
{ | ||
return m_compositeTransforms; | ||
} | ||
|
||
void ossim2dTo2dCompositeTransform::forward(const ossimDpt& input, | ||
ossimDpt& output) const | ||
{ | ||
ossimDpt tempInput = input; | ||
output = input; | ||
|
||
for(auto transform:m_compositeTransforms) | ||
{ | ||
transform->forward(tempInput, output); | ||
tempInput=output; | ||
} | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
void ossim2dTo2dCompositeTransform::forward(ossimDpt& modify_this) const | ||
{ | ||
forward(ossimDpt(modify_this), modify_this); | ||
} | ||
|
||
/** | ||
* inverse transform just passes the point to the output. | ||
*/ | ||
void ossim2dTo2dCompositeTransform::inverse(const ossimDpt& input, | ||
ossimDpt& output) const | ||
{ | ||
ossimDpt tempInput = input; | ||
output = input; | ||
|
||
for(CompositeTransformList::const_reverse_iterator iter = m_compositeTransforms.rbegin(); | ||
iter != m_compositeTransforms.rend(); | ||
++iter | ||
) | ||
{ | ||
(*iter)->inverse(tempInput, output); | ||
tempInput = output; | ||
} | ||
} | ||
|
||
/** | ||
* inverse transform nothing is modified on the input point. | ||
*/ | ||
void ossim2dTo2dCompositeTransform::inverse(ossimDpt& modify_this) const | ||
{ | ||
inverse(ossimDpt(modify_this), modify_this); | ||
} | ||
|
||
bool ossim2dTo2dCompositeTransform::saveState(ossimKeywordlist& kwl, const char* prefix)const | ||
{ | ||
bool result = ossim2dTo2dTransform::saveState(kwl, prefix); | ||
ossim_uint64 idx = 0; | ||
|
||
for(; idx < m_compositeTransforms.size();++idx) | ||
{ | ||
ossimString newPrefix(prefix); | ||
|
||
newPrefix += ossimString("object") + | ||
ossimString::toString(idx) + | ||
ossimString("."); | ||
result &= m_compositeTransforms[idx]->saveState(kwl, newPrefix.c_str()); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
bool ossim2dTo2dCompositeTransform::loadState(const ossimKeywordlist& kwl, const char* prefix) | ||
{ | ||
bool result = ossim2dTo2dTransform::loadState(kwl, prefix); | ||
|
||
std::vector<ossimString> prefixValues; | ||
clear(); | ||
kwl.getSubstringKeyList(prefixValues, ossimString("^(")+ossimString(prefix)+"object[0-9]+.)"); | ||
|
||
for(auto newPrefix:prefixValues) | ||
{ | ||
ossimRefPtr<ossim2dTo2dTransform> trans = ossim2dTo2dTransformRegistry::instance()->createTransform(kwl, newPrefix.c_str()); | ||
if(trans) | ||
{ | ||
add(trans); | ||
} | ||
} | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters