All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ContrastEnhancement.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2011 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/serialization/se/ContrastEnhancement.cpp
22 
23  \brief Support for ContrastEnhancement serialization.
24 */
25 
26 // TerraLib
27 #include "../../se/ContrastEnhancement.h"
28 #include "../../xml/Reader.h"
29 #include "../../xml/Writer.h"
30 #include "ContrastEnhancement.h"
31 #include "Utils.h"
32 
33 // STL
34 #include <cassert>
35 #include <memory>
36 
38 {
39  assert(reader.getNodeType() == te::xml::START_ELEMENT);
40  assert(reader.getElementLocalName() == "ContrastEnhancement");
41 
42  reader.next();
43 
44  std::auto_ptr<te::se::ContrastEnhancement> ce(new te::se::ContrastEnhancement);
45  ce->setContrastEnhancementType(te::se::ContrastEnhancement::ENHANCEMENT_NONE);
46 
47  if(reader.getElementLocalName() == "Histogram")
48  {
49  ce->setContrastEnhancementType(te::se::ContrastEnhancement::ENHANCEMENT_HISTOGRAM);
50  reader.next();
51  }
52  else if(reader.getElementLocalName() == "Normalize")
53  {
54  ce->setContrastEnhancementType(te::se::ContrastEnhancement::ENHANCEMENT_NORMALIZE);
55  reader.next();
56  }
57 
58  if(reader.getElementLocalName() == "GammaValue")
59  {
60  reader.next();
61  assert(reader.getNodeType() == te::xml::VALUE);
62  ce->setGammaValue(reader.getElementValueAsDouble());
63  reader.next();
64  assert(reader.getNodeType() == te::xml::END_ELEMENT);
65  reader.next();
66  }
67 
68  assert(reader.getNodeType() == te::xml::END_ELEMENT);
69  reader.next();
70 
71  return ce.release();
72 }
73 
75 {
76  if(ce == 0)
77  return;
78 
79  writer.writeStartElement("se:ContrastEnhancement");
81  switch(type)
82  {
84  break;
85 
87  writer.writeElement("se:Histogram", ""); // TODO: Writer method to writer a empty element, i.e. <Histogram/>
88  break;
89 
91  writer.writeElement("se:Normalize", ""); // TODO: Writer method to writer a empty element, i.e. <Normalize/>
92  break;
93  }
94 
95  writer.writeElement("se:GammaValue", ce->getGammaValue());
96 
97  writer.writeEndElement("se:ContrastEnhancement");
98 }
Utility methods for Symbology serialization.
ContrastEnhancementType
The type of contrast enhancement.
This class models a XML reader object.
Definition: Reader.h:55
virtual bool next()=0
It gets the next event to be read.
ContrastEnhancement defines the &#39;stretching&#39; of contrast for a channel of a false-color image or for ...
virtual double getElementValueAsDouble() const
It returns the element data value in the case of VALUE node.
Definition: Reader.cpp:37
virtual void writeStartElement(const std::string &qName)
Definition: Writer.cpp:44
virtual void writeEndElement(const std::string &qName)
Definition: Writer.cpp:156
TESERIALIZATIONEXPORT te::se::ContrastEnhancement * ReadContrastEnhancement(te::xml::Reader &reader)
TESERIALIZATIONEXPORT void Save(const te::fe::Filter *filter, te::xml::Writer &writer)
Definition: Filter.cpp:54
virtual void writeElement(const std::string &qName, const std::string &value)
Definition: Writer.cpp:54
ContrastEnhancementType getContrastEnhancementType() const
virtual NodeType getNodeType() const =0
It return the type of node read.
ContrastEnhancement defines the &#39;stretching&#39; of contrast for a channel of a false-color image or for ...
virtual std::string getElementLocalName() const =0
It returns the local part of the element name in the case of an element node.
This class models a XML writer object.
Definition: Writer.h:52