ChannelMaps.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "Channels/ChannelMaps.H"
00039 #include "Channels/ChannelBase.H"
00040 #include "Channels/SingleChannel.H"
00041 #include "Channels/ComplexChannel.H"
00042 #include "Channels/IntegerSimpleChannel.H"
00043 #include "Channels/IntegerComplexChannel.H"
00044 #include "Neuro/EnvVisualCortex.H"
00045
00046
00047 ChannelMaps::ChannelMaps(ChannelBase* chan, const std::string& prefix) :
00048 itsOutputMap(), itsSubmaps(), itsRawCSmaps(), itsPyramid(), itsSubchanMaps()
00049 {
00050 const std::string newprefix = prefix.empty() ? "" : prefix + ":";
00051
00052 if (prefix.empty())
00053 itsOutputMap = NamedImage<float>(chan->getOutput(), "SaliencyMap");
00054 else
00055 {
00056 if (chan->outputAvailable())
00057 itsOutputMap = NamedImage<float>(chan->getOutput(), newprefix + chan->tagName());
00058 else
00059 itsOutputMap = NamedImage<float>(newprefix + chan->tagName());
00060 }
00061
00062
00063 if (SingleChannel* ch = dynamic_cast<SingleChannel*>(chan))
00064 {
00065
00066 const uint n = ch->numSubmaps();
00067 for (uint i = 0; i < n; ++i)
00068 {
00069 const std::string name = newprefix + ch->getSubmapNameShort(i);
00070 if (ch->outputAvailable())
00071 {
00072 itsSubmaps.push_back(NamedImage<float>(ch->getSubmap(i), name));
00073 itsRawCSmaps.push_back(NamedImage<float>(ch->getRawCSmap(i), name + "raw"));
00074 }
00075 else
00076 {
00077 itsSubmaps.push_back(NamedImage<float>(name));
00078 itsRawCSmaps.push_back(NamedImage<float>(name + "raw"));
00079 }
00080 }
00081
00082
00083 if (ch->hasPyramid()) itsPyramid = ch->pyramid(0);
00084 }
00085 else if (ComplexChannel* ch = dynamic_cast<ComplexChannel*>(chan))
00086 {
00087 const uint n = ch->numChans();
00088 for (uint i = 0; i < n; ++i)
00089 itsSubchanMaps.push_back(rutz::make_shared(new ChannelMaps(ch->subChan(i).get(), newprefix + ch->tagName())));
00090 }
00091 else if (IntegerSimpleChannel* ch = dynamic_cast<IntegerSimpleChannel*>(chan))
00092 {
00093
00094 const uint n = ch->numSubmaps();
00095 for (uint i = 0; i < n; ++i)
00096 {
00097 const std::string name = newprefix + ch->getSubmapNameShort(i);
00098 if (ch->outputAvailable())
00099 {
00100 itsSubmaps.push_back(NamedImage<float>(ch->getSubmap(i), name));
00101 itsRawCSmaps.push_back(NamedImage<float>(ch->getRawCSmap(i), name + "raw"));
00102 }
00103 else
00104 {
00105 itsSubmaps.push_back(NamedImage<float>(name));
00106 itsRawCSmaps.push_back(NamedImage<float>(name + "raw"));
00107 }
00108 }
00109
00110
00111 itsPyramid = ImageSet<float>(ch->intgPyramid());
00112 }
00113 else if (IntegerComplexChannel* ch = dynamic_cast<IntegerComplexChannel*>(chan))
00114 {
00115 const uint n = ch->numChans();
00116 for (uint i = 0; i < n; ++i)
00117 itsSubchanMaps.push_back(rutz::make_shared(new ChannelMaps(ch->subChan(i).get(), newprefix + ch->tagName())));
00118 }
00119 else if (ChannelBase* ch = dynamic_cast<ChannelBase*>(chan))
00120 {
00121
00122 const uint n = ch->numSubmaps();
00123 for (uint i = 0; i < n; ++i)
00124 {
00125 const std::string name = newprefix + ch->getSubmapNameShort(i);
00126 if (ch->outputAvailable())
00127 itsSubmaps.push_back(NamedImage<float>(ch->getSubmap(i), name));
00128 else
00129 itsSubmaps.push_back(NamedImage<float>(name));
00130 }
00131 }
00132 else LFATAL("Inconsistency in Channel hierarchy!");
00133 }
00134
00135
00136 ChannelMaps::ChannelMaps(const NamedImage<float>& outmap) :
00137 itsOutputMap(outmap), itsSubmaps(), itsRawCSmaps(), itsSubchanMaps()
00138 { }
00139
00140
00141 ChannelMaps::ChannelMaps(EnvVisualCortexFloat* v, const std::string& prefix) :
00142 itsOutputMap(), itsSubmaps(), itsRawCSmaps(), itsSubchanMaps()
00143 {
00144 const std::string npfx = prefix.empty() ? "VisualCortex:" : prefix + ":";
00145
00146
00147 itsOutputMap = NamedImage<float>(v->getVCXmap(), "SaliencyMap");
00148 itsSubchanMaps.push_back(rutz::make_shared(new ChannelMaps(NamedImage<float>(v->getImap(), npfx + "intensity"))));
00149 itsSubchanMaps.push_back(rutz::make_shared(new ChannelMaps(NamedImage<float>(v->getCmap(), npfx + "color"))));
00150 itsSubchanMaps.push_back(rutz::make_shared(new ChannelMaps(NamedImage<float>(v->getOmap(), npfx + "orientation"))));
00151 #ifdef ENV_WITH_DYNAMIC_CHANNELS
00152 itsSubchanMaps.push_back(rutz::make_shared(new ChannelMaps(NamedImage<float>(v->getFmap(), npfx + "flicker"))));
00153 itsSubchanMaps.push_back(rutz::make_shared(new ChannelMaps(NamedImage<float>(v->getMmap(), npfx + "motion"))));
00154 #endif
00155 }
00156
00157
00158 ChannelMaps::~ChannelMaps()
00159 { }
00160
00161
00162 const NamedImage<float>& ChannelMaps::getMap() const
00163 { return itsOutputMap; }
00164
00165
00166 uint ChannelMaps::numSubchans() const
00167 { return itsSubchanMaps.size(); }
00168
00169
00170 rutz::shared_ptr<ChannelMaps> ChannelMaps::subChanMaps(const uint idx) const
00171 {
00172 ASSERT(idx < itsSubchanMaps.size());
00173 return itsSubchanMaps[idx];
00174 }
00175
00176
00177 uint ChannelMaps::numSubmaps() const
00178 {
00179 uint count = 0;
00180 for (uint i = 0; i < itsSubchanMaps.size(); ++i)
00181 count += itsSubchanMaps[i]->numSubmaps();
00182
00183 return count + itsSubmaps.size();
00184 }
00185
00186
00187 const NamedImage<float>& ChannelMaps::getSubmap(const uint idx) const
00188 {
00189 if (itsSubchanMaps.size())
00190 {
00191 uint subchan = 0, subidx = 0;
00192 lookupSubmap(idx, subchan, subidx);
00193 return itsSubchanMaps[subchan]->getSubmap(subidx);
00194 }
00195 else
00196 {
00197 ASSERT(idx < itsSubmaps.size());
00198 return itsSubmaps[idx];
00199 }
00200 }
00201
00202
00203 const NamedImage<float>& ChannelMaps::getRawCSmap(const uint idx) const
00204 {
00205 if (itsSubchanMaps.size())
00206 {
00207 uint subchan = 0, subidx = 0;
00208 lookupSubmap(idx, subchan, subidx);
00209 return itsSubchanMaps[subchan]->getRawCSmap(subidx);
00210 }
00211 else
00212 {
00213 ASSERT(idx < itsRawCSmaps.size());
00214 return itsRawCSmaps[idx];
00215 }
00216 }
00217
00218
00219 void ChannelMaps::lookupSubmap(const uint idx, uint& subchan, uint& subidx) const
00220 {
00221 uint offset = 0;
00222 for (subchan = 0; subchan < itsSubchanMaps.size(); ++subchan)
00223 {
00224 subidx = idx - offset;
00225 const uint nsub = itsSubchanMaps[subchan]->numSubmaps();
00226 if (subidx < nsub) return;
00227 else offset += nsub;
00228 }
00229 LFATAL("invalid submap index: %d", idx);
00230 }
00231
00232
00233 bool ChannelMaps::hasPyramid() const
00234 { return itsPyramid.isNonEmpty(); }
00235
00236
00237 const ImageSet<float>& ChannelMaps::getPyramid() const
00238 { return itsPyramid; }
00239
00240
00241
00242
00243
00244
00245
00246