forked from ossimlabs/ossim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ossimFusionCombiner.cpp
201 lines (177 loc) · 6.2 KB
/
ossimFusionCombiner.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//*******************************************************************
// Copyright (C) 2000 ImageLinks Inc.
//
// License: See top level LICENSE.txt file.
//
// Author: Garrett Potts
//
// Description: implementation for base fusion
//
//*************************************************************************
// $Id: ossimFusionCombiner.cpp 13312 2008-07-27 01:26:52Z gpotts $
#include <ossim/imaging/ossimFusionCombiner.h>
#include <ossim/imaging/ossimImageDataFactory.h>
RTTI_DEF1(ossimFusionCombiner, "ossimFusionCombiner", ossimImageCombiner);
ossimFusionCombiner::ossimFusionCombiner()
:ossimImageCombiner(NULL, 2, 0, true, false),
theTile(NULL),
theNormTile(NULL),
theNormIntensity(NULL),
theInputConnection(NULL),
theIntensityConnection(NULL)
{
}
ossimFusionCombiner::ossimFusionCombiner(ossimObject* owner)
:ossimImageCombiner(owner, 2, 0, true, false),
theTile(NULL),
theNormTile(NULL),
theNormIntensity(NULL),
theInputConnection(NULL),
theIntensityConnection(NULL)
{}
ossimFusionCombiner::~ossimFusionCombiner()
{
theInputConnection = NULL;
theIntensityConnection = NULL;
}
ossimIrect ossimFusionCombiner::getBoundingRect(ossim_uint32 resLevel) const
{
ossimIrect result;
ossimIrect colorRect;
result.makeNan();
if(theIntensityConnection)
{
result = theIntensityConnection->getBoundingRect(resLevel);
}
if(theInputConnection)
{
colorRect = theInputConnection->getBoundingRect(resLevel);
if(theIntensityConnection)
{
result = result.clipToRect(colorRect);
}
else
{
result = colorRect;
}
}
return result;
}
bool ossimFusionCombiner::canConnectMyInputTo(ossim_int32 inputIndex,
const ossimConnectableObject* object)const
{
return ((inputIndex<2)&&
(PTR_CAST(ossimImageSource, object)||!object));
}
ossimScalarType ossimFusionCombiner::getOutputScalarType() const
{
if(theInputConnection)
{
return theInputConnection->getOutputScalarType();
}
return ossimImageCombiner::getOutputScalarType();
}
ossimRefPtr<ossimImageData> ossimFusionCombiner::getNormIntensity(
const ossimIrect& rect,
ossim_uint32 resLevel)
{
if(theIntensityConnection)
{
ossimRefPtr<ossimImageData> data =
theIntensityConnection->getTile(rect, resLevel);
if(data.valid() && data->getBuf())
{
if(!theNormIntensity.valid())
{
theNormIntensity = new ossimImageData(this,
OSSIM_NORMALIZED_FLOAT,
data->getNumberOfBands(),
rect.width(),
rect.height());
theNormIntensity->initialize();
}
theNormIntensity->setImageRectangleAndBands(rect,
data->getNumberOfBands());
data->copyTileToNormalizedBuffer((float*)theNormIntensity->getBuf());
theNormIntensity->setDataObjectStatus(data->getDataObjectStatus());
return theNormIntensity;
}
}
return ossimRefPtr<ossimImageData>();
}
ossimRefPtr<ossimImageData> ossimFusionCombiner::getNormTile(
const ossimIrect& rect,
ossim_uint32 resLevel)
{
if(theInputConnection)
{
ossimRefPtr<ossimImageData> data = theInputConnection->getTile(rect,
resLevel);
if(data.valid() && data->getBuf())
{
// make sure the tile result is updated if changed.
//
if((data->getNumberOfBands() != theTile->getNumberOfBands())||
(data->getScalarType() != theTile->getScalarType()))
{
theTile = ossimImageDataFactory::instance()->create(this,
theInputConnection);
theTile->initialize();
}
if(!theNormTile.valid())
{
theNormTile = new ossimImageData(this,
OSSIM_NORMALIZED_FLOAT,
data->getNumberOfBands(),
rect.width(),
rect.height());
theNormTile->initialize();
}
else if(theNormTile->getNumberOfBands() != data->getNumberOfBands())
{
theNormTile = new ossimImageData(this,
OSSIM_NORMALIZED_FLOAT,
data->getNumberOfBands(),
rect.width(),
rect.height());
theNormTile->initialize();
}
theNormTile->setImageRectangleAndBands(rect,
data->getNumberOfBands());
data->copyTileToNormalizedBuffer((float*)theNormTile->getBuf());
theNormTile->setDataObjectStatus(data->getDataObjectStatus());
return theNormTile;
}
}
return ossimRefPtr<ossimImageData>();
}
void ossimFusionCombiner::initialize()
{
ossimImageCombiner::initialize();
theInputConnection = PTR_CAST(ossimImageSource, getInput(0));
theIntensityConnection = PTR_CAST(ossimImageSource, getInput(1));
if(getInput(0)&&getInput(1))
{
ossimImageSource* temp = PTR_CAST(ossimImageSource,
getInput(0));
ossimImageSource* temp2 = PTR_CAST(ossimImageSource,
getInput(1));
if(temp&&temp2)
{
if((temp->getNumberOfOutputBands()==1)&&
(temp2->getNumberOfOutputBands()!=1))
{
theIntensityConnection = PTR_CAST(ossimImageSource,
getInput(0));
theInputConnection = PTR_CAST(ossimImageSource,
getInput(1));
}
}
}
if(theInputConnection)
{
theTile = ossimImageDataFactory::instance()->create(this,
theInputConnection);
theTile->initialize();
}
}