All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ChannelSelection.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/ChannelSelection.cpp
22 
23  \brief Support for ChannelSelection serialization.
24 */
25 
26 // TerraLib
27 #include "../../se/ChannelSelection.h"
28 #include "../../xml/Reader.h"
29 #include "../../xml/Writer.h"
30 #include "ChannelSelection.h"
31 #include "SelectedChannel.h"
32 #include "Utils.h"
33 
34 // STL
35 #include <cassert>
36 #include <memory>
37 
39 {
40  assert(reader.getNodeType() == te::xml::START_ELEMENT);
41  assert(reader.getElementLocalName() == "ChannelSelection");
42 
43  reader.next();
44 
45  std::auto_ptr<te::se::ChannelSelection> cs(new te::se::ChannelSelection);
46  cs->setColorCompositionType(te::se::UNKNOWN_COMPOSITION);
47 
48  // GrayChannel
49  if(reader.getElementLocalName() == "GrayChannel")
50  {
51  cs->setGrayChannel(ReadSelectedChannel(reader));
52  cs->setColorCompositionType(te::se::GRAY_COMPOSITION);
53 
54  assert(reader.getNodeType() == te::xml::END_ELEMENT);
55  reader.next();
56 
57  return cs.release();
58  }
59 
60  std::size_t nChannels = 0; // To count the number of channels
61 
62  // RedChannel
63  if(reader.getElementLocalName() == "RedChannel")
64  {
65  cs->setRedChannel(ReadSelectedChannel(reader));
66  cs->setColorCompositionType(te::se::RED_COMPOSITION);
67  nChannels++;
68  }
69 
70  // GreenChannel
71  if(reader.getElementLocalName() == "GreenChannel")
72  {
73  cs->setGreenChannel(ReadSelectedChannel(reader));
74  cs->setColorCompositionType(te::se::GREEN_COMPOSITION);
75  nChannels++;
76  }
77 
78  // BlueChannel
79  if(reader.getElementLocalName() == "BlueChannel")
80  {
81  cs->setBlueChannel(ReadSelectedChannel(reader));
82  cs->setColorCompositionType(te::se::BLUE_COMPOSITION);
83  nChannels++;
84  }
85 
86  assert(nChannels > 0);
87 
88  // Adjusting...
89  if(nChannels > 1)
90  nChannels == 3 ? cs->setColorCompositionType(te::se::RGB_COMPOSITION) : cs->setColorCompositionType(te::se::UNKNOWN_COMPOSITION);
91 
92  assert(reader.getNodeType() == te::xml::END_ELEMENT);
93  reader.next();
94 
95  return cs.release();
96 }
97 
99 {
100  if(cs == 0)
101  return;
102 
103  writer.writeStartElement("se:ChannelSelection");
104 
106  {
107  WriteSelectedChannelHelper("se:GrayChannel", cs->getGrayChannel(), writer);
108  }
110  {
111  WriteSelectedChannelHelper("se:RedChannel", cs->getRedChannel(), writer);
112  }
114  {
115  WriteSelectedChannelHelper("se:GreenChannel", cs->getGreenChannel(), writer);
116  }
118  {
119  WriteSelectedChannelHelper("se:BlueChannel", cs->getBlueChannel(), writer);
120  }
122  {
123  WriteSelectedChannelHelper("se:RedChannel", cs->getRedChannel(), writer);
124  WriteSelectedChannelHelper("se:GreenChannel", cs->getGreenChannel(), writer);
125  WriteSelectedChannelHelper("se:BlueChannel", cs->getBlueChannel(), writer);
126  }
127 
128  writer.writeEndElement("se:ChannelSelection");
129 }
Support for SelectedChannel serialization.
ChannelSelection specifies the false-color channel selection for a multi-spectral raster source (such...
Utility methods for Symbology serialization.
SelectedChannel * getRedChannel() const
This class models a XML reader object.
Definition: Reader.h:55
virtual bool next()=0
It gets the next event to be read.
void WriteSelectedChannelHelper(const std::string &elementName, const te::se::SelectedChannel *sc, te::xml::Writer &writer)
Definition: Utils.cpp:122
virtual void writeStartElement(const std::string &qName)
Definition: Writer.cpp:44
ColorCompositionType getColorCompositionType() const
TESERIALIZATIONEXPORT te::se::SelectedChannel * ReadSelectedChannel(te::xml::Reader &reader)
virtual void writeEndElement(const std::string &qName)
Definition: Writer.cpp:156
TESERIALIZATIONEXPORT void Save(const te::fe::Filter *filter, te::xml::Writer &writer)
Definition: Filter.cpp:54
TESERIALIZATIONEXPORT te::se::ChannelSelection * ReadChannelSelection(te::xml::Reader &reader)
SelectedChannel * getBlueChannel() const
SelectedChannel * getGreenChannel() const
ChannelSelection specifies the false-color channel selection for a multi-spectral raster source (such...
SelectedChannel * getGrayChannel() const
virtual NodeType getNodeType() const =0
It return the type of node read.
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