OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimHistogramWriter.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Author: Garrett Potts
8 //
9 //*************************************************************************
10 // $Id: ossimHistogramWriter.cpp 20118 2011-10-05 13:50:55Z dburken $
19 #include <ossim/base/ossimTrace.h>
20 
21 static ossimTrace traceDebug("ossimHistogramWriter:debug");
23 {
24 public:
26  :thePassonTo(passon)
27  {
28  }
30  {
31  if(thePassonTo)
32  {
33  event.setObject(thePassonTo);
34  thePassonTo->fireEvent(event);
35  }
36  }
37 
39 
40 };
41 
43  "ossimHistogramWriter",
47 
49  ossimObject* owner)
50  : ossimOutputSource(owner,
51  1,
52  0,
53  true,
54  false),
55  theAreaOfInterest(),
56  theFilename(),
57  theFileStream(0),
58  theProcessListener(0),
59  theHistogramSource(0)
60 {
62 
64  connectMyInputTo(0, inputSource);
65 }
66 
68 {
69  if(isOpen())
70  {
71  close();
72  }
74  {
75  delete theProcessListener;
77  }
78 
79  // This does not need to be deleted here. Simply stored for abort.
81  {
83  }
84 }
85 
87 {
88  theAreaOfInterest = rect;
89 }
90 
92 {
93  return this;
94 }
95 
97 {
98  return (theFileStream != 0);
99 }
100 
102 {
103  if(isOpen())
104  {
105  close();
106  }
107 
109 
110  return theFileStream->good();
111 }
112 
114 {
115  return ossimOutputSource::open(filename);
116 }
117 
119 {
120  delete theFileStream;
121  theFileStream = 0;
122 }
123 
125 {
127  setFilename(outputName);
128 }
129 
131 {
132  theFilename = filename;
133 }
134 
136  ossim_int32 inputIndex, const ossimConnectableObject* object)const
137 {
138  return (object&&(inputIndex == 0)&&
139  (PTR_CAST(ossimHistogramSource, object)||
140  PTR_CAST(ossimImageSource, object)));
141 }
142 
144 {
145  return this;
146 }
147 
150 {
151  // we will raise the event if its coming from our
152  // input. This means that we are connected to a
153  // ossimHistogramSource.
154  //
155  if(event.getObject() != this)
156  {
159  }
160 }
161 
163  ossimConnectionEvent& event)
164 {
165  if(event.getObject() == this)
166  {
167  if(event.getOldObject())
168  {
169  event.getOldObject()->removeListener((ossimProcessListener*)this);
170  }
171  if(getInput(0)&&
173  {
175  }
176  }
177 }
178 
180  ossimConnectionEvent& event)
181 {
182  if(event.getOldObject()&&
184  {
185  event.getOldObject()->removeListener((ossimProcessListener*)this);
186  }
187 }
188 
190  const char* prefix)const
191 {
192  bool result = ossimOutputSource::saveState(kwl, prefix);
193 
194 
195  return result;
196 }
197 
199  const char* prefix)
200 {
201  bool result = ossimOutputSource::loadState(kwl, prefix);
202 
203  if(result)
204  {
205  if(!getNumberOfInputs())
206  {
208  }
209  }
210 
211  return result;
212 }
213 
215 {
216  writeHistogram();
217 
218  return true;
219 }
220 
222 {
223  if(!getInput(0))
224  {
225  cerr << "ossimHistogramWriter::writeHistogram is not connected" << endl;
226  return;
227  }
229  bool deleteHistoSource = false;
230  if(!histoSource)
231  {
232  histoSource = new ossimImageHistogramSource;
233  histoSource->connectMyInputTo(0, getInput(0));
234  histoSource->enableSource();
235  deleteHistoSource = true;
236 
237  //---
238  // Capture the pointer for abort call. Note a ossimHistogramSource has
239  // no abort so the abort will only work through the
240  // ossimImageHistogramSource pointer.
241  //---
243  }
244 
245  // Capture the pointer for abort call.
246  theHistogramSource = histoSource;
247 
248  histoSource->addListener( theProcessListener);
249 
251 
252  // Don't write histogram if abort flag was set...
253  if(histo.valid() && !isAborted() )
254  {
255  ossimKeywordlist kwl;
256  histo->saveState(kwl);
257  if(!isOpen())
258  {
259  open();
260  if(!isOpen())
261  {
262  if(traceDebug())
263  {
264  ossimNotify(ossimNotifyLevel_WARN) << "unable to open file " << theFilename << endl;
265  }
266  }
267  }
268  if( isOpen() )
269  {
271  }
272  }
273  histoSource->removeListener(theProcessListener);
274 
275  if(deleteHistoSource)
276  {
277  delete histoSource;
278  histoSource = 0;
279  }
280  theHistogramSource = 0;
281 
282  close();
283 }
284 
286 {
287  //---
288  // Call base abort. This sets the status to PROCESS_STATUS_ABORT_REQUEST so the processor
289  // knows to abort.
290  //---
292 
293  // Propagate to histo source.
294  if (theHistogramSource)
295  {
296  ossimImageHistogramSource* histoSource =
298  if (histoSource)
299  {
300  histoSource->abort();
301  }
302  }
303 
304  //---
305  // Now set status to "ABORTED" so ossimProcessInterface::isAborted returns true so the
306  // writeHistogram method doesn't write the file if the process was aborted.
307  //---
309 }
virtual void setNumberOfInputs(ossim_int32 numberOfInputs)
Will set the number of inputs.
virtual bool addListener(ossimListener *listener)
Represents serializable keyword/value map.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
bool valid() const
Definition: ossimRefPtr.h:75
virtual void setPercentComplete(double percentComplete)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual void setProcessStatus(ossimProcessStatus processStatus)
virtual void fireEvent(ossimEvent &event)
ossimHistogramWriterProcessListener * theProcessListener
virtual bool isOpen() const
virtual void setOutputName(const ossimString &outputName)
ossimConnectableObject * getInput(ossim_uint32 index=0)
returns the object at the specified index.
bool canConnectMyInputTo(ossim_int32 inputIndex, const ossimConnectableObject *object) const
required to be overriden by derived classes
void setAreaOfInterest(const ossimIrect &rect)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
const ossimObject * getObject() const
This is the originating object that originally produced the event.
Definition: ossimEvent.cpp:64
std::ofstream * theFileStream
virtual void disconnectInputEvent(ossimConnectionEvent &event)
#define PTR_CAST(T, p)
Definition: ossimRtti.h:321
virtual void enableSource()
Definition: ossimSource.cpp:84
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
virtual void writeToStream(std::ostream &out) const
ossimHistogramWriter(ossimImageSource *inputSource=0, ossimObject *owner=0)
ossimHistogramSource * theHistogramSource
stored for abort call only.
virtual ossimConnectableObject * getOldObject(ossim_uint32 i=0)
ossimHistogramWriterProcessListener(ossimConnectableObject *passon)
void setCurrentMessage(const ossimString &message)
virtual void connectInputEvent(ossimConnectionEvent &event)
virtual bool open()=0
void makeNan()
Definition: ossimIrect.h:329
virtual ossim_uint32 getNumberOfInputs() const
Returns the number of input objects.
virtual void processProgressEvent(ossimProcessProgressEvent &event)
RTTI_DEF3(ossimHistogramWriter, "ossimHistogramWriter", ossimOutputSource, ossimProcessInterface, ossimConnectableObjectListener)
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
virtual ossimObject * getObject()
std::basic_ofstream< char > ofstream
Class for char output file streams.
Definition: ossimIosFwd.h:47
virtual void abort()
Overrides base to pass on abort to theHistogramSource.
virtual void setFilename(const ossimFilename &filename)
virtual void processProgressEvent(ossimProcessProgressEvent &event)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual void setOutputName(const ossimString &outputName)
virtual ossimRefPtr< ossimMultiResLevelHistogram > getHistogram()
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
friend class ossimHistogramWriterProcessListener
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
int ossim_int32
virtual bool removeListener(ossimListener *listener)