config.cc
Go to the documentation of this file.
00001 /*
00002  * This file is part of the rc_genicam_api package.
00003  *
00004  * Copyright (c) 2017 Roboception GmbH
00005  * All rights reserved
00006  *
00007  * Author: Heiko Hirschmueller
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright notice,
00013  * this list of conditions and the following disclaimer.
00014  *
00015  * 2. Redistributions in binary form must reproduce the above copyright notice,
00016  * this list of conditions and the following disclaimer in the documentation
00017  * and/or other materials provided with the distribution.
00018  *
00019  * 3. Neither the name of the copyright holder nor the names of its contributors
00020  * may be used to endorse or promote products derived from this software without
00021  * specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  * POSSIBILITY OF SUCH DAMAGE.
00034  */
00035 
00036 #include "config.h"
00037 #include "buffer.h"
00038 
00039 #include <stdexcept>
00040 #include <iomanip>
00041 
00042 #include "Base/GCException.h"
00043 
00044 #include <GenApi/ChunkAdapterGEV.h>
00045 #include <GenApi/ChunkAdapterU3V.h>
00046 #include <GenApi/ChunkAdapterGeneric.h>
00047 
00048 #include <rc_genicam_api/pixel_formats.h>
00049 
00050 namespace rcg
00051 {
00052 
00053 bool callCommand(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
00054                  bool exception)
00055 {
00056   bool ret=false;
00057 
00058   try
00059   {
00060     GenApi::INode *node=nodemap->_GetNode(name);
00061 
00062     if (node != 0)
00063     {
00064       if (GenApi::IsWritable(node))
00065       {
00066         GenApi::ICommand *val=dynamic_cast<GenApi::ICommand *>(node);
00067 
00068         if (val != 0)
00069         {
00070           val->Execute();
00071           ret=true;
00072         }
00073         else if (exception)
00074         {
00075           throw std::invalid_argument(std::string("Feature not a command: ")+name);
00076         }
00077       }
00078       else if (exception)
00079       {
00080         throw std::invalid_argument(std::string("Feature not writable: ")+name);
00081       }
00082     }
00083     else if (exception)
00084     {
00085       throw std::invalid_argument(std::string("Feature not found: ")+name);
00086     }
00087   }
00088   catch (const GENICAM_NAMESPACE::GenericException &ex)
00089   {
00090     if (exception)
00091     {
00092       throw std::invalid_argument(ex.what());
00093     }
00094   }
00095 
00096   return ret;
00097 }
00098 
00099 bool setBoolean(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
00100                 bool value, bool exception)
00101 {
00102   bool ret=false;
00103 
00104   try
00105   {
00106     GenApi::INode *node=nodemap->_GetNode(name);
00107 
00108     if (node != 0)
00109     {
00110       if (GenApi::IsWritable(node))
00111       {
00112         GenApi::IBoolean *val=dynamic_cast<GenApi::IBoolean *>(node);
00113 
00114         if (val != 0)
00115         {
00116           val->SetValue(value);
00117           ret=true;
00118         }
00119         else if (exception)
00120         {
00121           throw std::invalid_argument(std::string("Feature not boolean: ")+name);
00122         }
00123       }
00124       else if (exception)
00125       {
00126         throw std::invalid_argument(std::string("Feature not writable: ")+name);
00127       }
00128     }
00129     else if (exception)
00130     {
00131       throw std::invalid_argument(std::string("Feature not found: ")+name);
00132     }
00133   }
00134   catch (const GENICAM_NAMESPACE::GenericException &ex)
00135   {
00136     if (exception)
00137     {
00138       throw std::invalid_argument(ex.what());
00139     }
00140   }
00141 
00142   return ret;
00143 }
00144 
00145 bool setInteger(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
00146                 int64_t value, bool exception)
00147 {
00148   bool ret=false;
00149 
00150   try
00151   {
00152     GenApi::INode *node=nodemap->_GetNode(name);
00153 
00154     if (node != 0)
00155     {
00156       if (GenApi::IsWritable(node))
00157       {
00158         GenApi::IInteger *val=dynamic_cast<GenApi::IInteger *>(node);
00159 
00160         if (val != 0)
00161         {
00162           val->SetValue(value);
00163           ret=true;
00164         }
00165         else if (exception)
00166         {
00167           throw std::invalid_argument(std::string("Feature not integer: ")+name);
00168         }
00169       }
00170       else if (exception)
00171       {
00172         throw std::invalid_argument(std::string("Feature not writable: ")+name);
00173       }
00174     }
00175     else if (exception)
00176     {
00177       throw std::invalid_argument(std::string("Feature not found: ")+name);
00178     }
00179   }
00180   catch (const GENICAM_NAMESPACE::GenericException &ex)
00181   {
00182     if (exception)
00183     {
00184       throw std::invalid_argument(ex.what());
00185     }
00186   }
00187 
00188   return ret;
00189 }
00190 
00191 bool setIPV4Address(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
00192                     const char *value, bool exception)
00193 {
00194   bool ret=false;
00195 
00196   try
00197   {
00198     GenApi::INode *node=nodemap->_GetNode(name);
00199 
00200     if (node != 0)
00201     {
00202       if (GenApi::IsWritable(node))
00203       {
00204         GenApi::IInteger *val=dynamic_cast<GenApi::IInteger *>(node);
00205 
00206         if (val != 0)
00207         {
00208           int64_t ip=0;
00209 
00210           std::stringstream in(value);
00211           std::string elem;
00212 
00213           for (int i=0; i<4; i++)
00214           {
00215             getline(in, elem, '.');
00216             ip=(ip<<8)|(stoi(elem)&0xff);
00217           }
00218 
00219           val->SetValue(ip);
00220           ret=true;
00221         }
00222         else if (exception)
00223         {
00224           throw std::invalid_argument(std::string("Feature not integer: ")+name);
00225         }
00226       }
00227       else if (exception)
00228       {
00229         throw std::invalid_argument(std::string("Feature not writable: ")+name);
00230       }
00231     }
00232     else if (exception)
00233     {
00234       throw std::invalid_argument(std::string("Feature not found: ")+name);
00235     }
00236   }
00237   catch (const GENICAM_NAMESPACE::GenericException &ex)
00238   {
00239     if (exception)
00240     {
00241       throw std::invalid_argument(ex.what());
00242     }
00243   }
00244 
00245   return ret;
00246 }
00247 
00248 bool setFloat(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
00249               double value, bool exception)
00250 {
00251   bool ret=false;
00252 
00253   try
00254   {
00255     GenApi::INode *node=nodemap->_GetNode(name);
00256 
00257     if (node != 0)
00258     {
00259       if (GenApi::IsWritable(node))
00260       {
00261         GenApi::IFloat *val=dynamic_cast<GenApi::IFloat *>(node);
00262 
00263         if (val != 0)
00264         {
00265           val->SetValue(value);
00266           ret=true;
00267         }
00268         else if (exception)
00269         {
00270           throw std::invalid_argument(std::string("Feature not float: ")+name);
00271         }
00272       }
00273       else if (exception)
00274       {
00275         throw std::invalid_argument(std::string("Feature not writable: ")+name);
00276       }
00277     }
00278     else if (exception)
00279     {
00280       throw std::invalid_argument(std::string("Feature not found: ")+name);
00281     }
00282   }
00283   catch (const GENICAM_NAMESPACE::GenericException &ex)
00284   {
00285     if (exception)
00286     {
00287       throw std::invalid_argument(ex.what());
00288     }
00289   }
00290 
00291   return ret;
00292 }
00293 
00294 bool setEnum(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
00295              const char *value, bool exception)
00296 {
00297   bool ret=false;
00298 
00299   try
00300   {
00301     GenApi::INode *node=nodemap->_GetNode(name);
00302 
00303     if (node != 0)
00304     {
00305       if (GenApi::IsWritable(node))
00306       {
00307         GenApi::IEnumeration *val=dynamic_cast<GenApi::IEnumeration *>(node);
00308 
00309         if (val != 0)
00310         {
00311           GenApi::IEnumEntry *entry=val->GetEntryByName(value);
00312 
00313           if (entry != 0)
00314           {
00315             val->SetIntValue(entry->GetValue());
00316 
00317             return true;
00318           }
00319           else if (exception)
00320           {
00321             throw std::invalid_argument(std::string("Enumeration '")+name+
00322                                         "' does not contain: "+value);
00323           }
00324         }
00325         else if (exception)
00326         {
00327           throw std::invalid_argument(std::string("Feature not enumeration: ")+name);
00328         }
00329       }
00330       else if (exception)
00331       {
00332         throw std::invalid_argument(std::string("Feature not writable: ")+name);
00333       }
00334     }
00335     else if (exception)
00336     {
00337       throw std::invalid_argument(std::string("Feature not found: ")+name);
00338     }
00339   }
00340   catch (const GENICAM_NAMESPACE::GenericException &ex)
00341   {
00342     if (exception)
00343     {
00344       throw std::invalid_argument(ex.what());
00345     }
00346   }
00347 
00348   return ret;
00349 }
00350 
00351 bool setString(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
00352                const char *value, bool exception)
00353 {
00354   bool ret=false;
00355 
00356   try
00357   {
00358     GenApi::INode *node=nodemap->_GetNode(name);
00359 
00360     if (node != 0)
00361     {
00362       if (GenApi::IsWritable(node))
00363       {
00364         switch (node->GetPrincipalInterfaceType())
00365         {
00366           case GenApi::intfIBoolean:
00367             {
00368               GenApi::IBoolean *p=dynamic_cast<GenApi::IBoolean *>(node);
00369 
00370               std::string v=std::string(value);
00371               if (v == "true" || v == "True" || v == "TRUE")
00372               {
00373                 p->SetValue(1);
00374               }
00375               else if (v == "false" || v == "False" || v == "FALSE")
00376               {
00377                 p->SetValue(0);
00378               }
00379               else
00380               {
00381                 p->SetValue(std::stoi(v));
00382               }
00383             }
00384             break;
00385 
00386           case GenApi::intfIInteger:
00387             {
00388               GenApi::IInteger *p=dynamic_cast<GenApi::IInteger *>(node);
00389 
00390               switch (p->GetRepresentation())
00391               {
00392                 case GenApi::HexNumber:
00393                   p->SetValue(std::stoll(std::string(value), 0, 16));
00394                   break;
00395 
00396                 case GenApi::IPV4Address:
00397                   {
00398                     int64_t ip=0;
00399 
00400                     std::stringstream in(value);
00401                     std::string elem;
00402 
00403                     for (int i=0; i<4; i++)
00404                     {
00405                       getline(in, elem, '.');
00406                       ip=(ip<<8)|(stoi(elem)&0xff);
00407                     }
00408 
00409                     p->SetValue(ip);
00410                   }
00411                   break;
00412 
00413                 case GenApi::MACAddress:
00414                   {
00415                     int64_t mac=0;
00416 
00417                     std::stringstream in(value);
00418                     std::string elem;
00419 
00420                     for (int i=0; i<4; i++)
00421                     {
00422                       getline(in, elem, ':');
00423                       mac=(mac<<8)|(stoi(elem, 0, 16)&0xff);
00424                     }
00425 
00426                     p->SetValue(mac);
00427                   }
00428                   break;
00429 
00430                 default:
00431                   p->SetValue(std::stoll(std::string(value)));
00432                   break;
00433               }
00434             }
00435             break;
00436 
00437           case GenApi::intfIFloat:
00438             {
00439               GenApi::IFloat *p=dynamic_cast<GenApi::IFloat *>(node);
00440               p->SetValue(std::stof(std::string(value)));
00441             }
00442             break;
00443 
00444           case GenApi::intfIEnumeration:
00445             {
00446               GenApi::IEnumeration *p=dynamic_cast<GenApi::IEnumeration *>(node);
00447               GenApi::IEnumEntry *entry=p->GetEntryByName(value);
00448 
00449               if (entry != 0)
00450               {
00451                 p->SetIntValue(entry->GetValue());
00452               }
00453               else if (exception)
00454               {
00455                 throw std::invalid_argument(std::string("Enumeration '")+name+
00456                                             "' does not contain: "+value);
00457               }
00458             }
00459             break;
00460 
00461           case GenApi::intfIString:
00462             {
00463               GenApi::IString *p=dynamic_cast<GenApi::IString *>(node);
00464               p->SetValue(value);
00465             }
00466             break;
00467 
00468           default:
00469             if (exception)
00470             {
00471               throw std::invalid_argument(std::string("Feature of unknown datatype: ")+name);
00472             }
00473             break;
00474         }
00475       }
00476       else if (exception)
00477       {
00478         throw std::invalid_argument(std::string("Feature not writable: ")+name);
00479       }
00480     }
00481     else if (exception)
00482     {
00483       throw std::invalid_argument(std::string("Feature not found: ")+name);
00484     }
00485   }
00486   catch (const GENICAM_NAMESPACE::GenericException &ex)
00487   {
00488     if (exception)
00489     {
00490       throw std::invalid_argument(ex.what());
00491     }
00492   }
00493 
00494   return ret;
00495 }
00496 
00497 bool getBoolean(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
00498                 bool exception, bool igncache)
00499 {
00500   bool ret=false;
00501 
00502   try
00503   {
00504     GenApi::INode *node=nodemap->_GetNode(name);
00505 
00506     if (node != 0)
00507     {
00508       if (GenApi::IsReadable(node))
00509       {
00510         GenApi::IBoolean *val=dynamic_cast<GenApi::IBoolean *>(node);
00511 
00512         if (val != 0)
00513         {
00514           ret=val->GetValue(false, igncache);
00515         }
00516         else if (exception)
00517         {
00518           throw std::invalid_argument(std::string("Feature not boolean: ")+name);
00519         }
00520       }
00521       else if (exception)
00522       {
00523         throw std::invalid_argument(std::string("Feature not readable: ")+name);
00524       }
00525     }
00526     else if (exception)
00527     {
00528       throw std::invalid_argument(std::string("Feature not found: ")+name);
00529     }
00530   }
00531   catch (const GENICAM_NAMESPACE::GenericException &ex)
00532   {
00533     if (exception)
00534     {
00535       throw std::invalid_argument(ex.what());
00536     }
00537   }
00538 
00539   return ret;
00540 }
00541 
00542 int64_t getInteger(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
00543                    int64_t *vmin, int64_t *vmax, bool exception, bool igncache)
00544 {
00545   int64_t ret=0;
00546 
00547   if (vmin != 0) *vmin=0;
00548   if (vmax != 0) *vmax=0;
00549 
00550   try
00551   {
00552     GenApi::INode *node=nodemap->_GetNode(name);
00553 
00554     if (node != 0)
00555     {
00556       if (GenApi::IsReadable(node))
00557       {
00558         GenApi::IInteger *val=dynamic_cast<GenApi::IInteger *>(node);
00559 
00560         if (val != 0)
00561         {
00562           ret=val->GetValue(false, igncache);
00563 
00564           if (vmin != 0) *vmin=val->GetMin();
00565           if (vmax != 0) *vmax=val->GetMax();
00566         }
00567         else if (exception)
00568         {
00569           throw std::invalid_argument(std::string("Feature not integer: ")+name);
00570         }
00571       }
00572       else if (exception)
00573       {
00574         throw std::invalid_argument(std::string("Feature not readable: ")+name);
00575       }
00576     }
00577     else if (exception)
00578     {
00579       throw std::invalid_argument(std::string("Feature not found: ")+name);
00580     }
00581   }
00582   catch (const GENICAM_NAMESPACE::GenericException &ex)
00583   {
00584     if (exception)
00585     {
00586       throw std::invalid_argument(ex.what());
00587     }
00588   }
00589 
00590   return ret;
00591 }
00592 
00593 double getFloat(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
00594                 double *vmin, double *vmax, bool exception, bool igncache)
00595 {
00596   double ret=0;
00597 
00598   if (vmin != 0) *vmin=0;
00599   if (vmax != 0) *vmax=0;
00600 
00601   try
00602   {
00603     GenApi::INode *node=nodemap->_GetNode(name);
00604 
00605     if (node != 0)
00606     {
00607       if (GenApi::IsReadable(node))
00608       {
00609         GenApi::IFloat *val=dynamic_cast<GenApi::IFloat *>(node);
00610 
00611         if (val != 0)
00612         {
00613           ret=val->GetValue(false, igncache);
00614 
00615           if (vmin != 0) *vmin=val->GetMin();
00616           if (vmax != 0) *vmax=val->GetMax();
00617         }
00618         else if (exception)
00619         {
00620           throw std::invalid_argument(std::string("Feature not float: ")+name);
00621         }
00622       }
00623       else if (exception)
00624       {
00625         throw std::invalid_argument(std::string("Feature not readable: ")+name);
00626       }
00627     }
00628     else if (exception)
00629     {
00630       throw std::invalid_argument(std::string("Feature not found: ")+name);
00631     }
00632   }
00633   catch (const GENICAM_NAMESPACE::GenericException &ex)
00634   {
00635     if (exception)
00636     {
00637       throw std::invalid_argument(ex.what());
00638     }
00639   }
00640 
00641   return ret;
00642 }
00643 
00644 std::string getEnum(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
00645                     bool exception)
00646 {
00647   std::string ret;
00648 
00649   try
00650   {
00651     GenApi::INode *node=nodemap->_GetNode(name);
00652 
00653     if (node != 0)
00654     {
00655       if (GenApi::IsReadable(node))
00656       {
00657         GenApi::IEnumeration *val=dynamic_cast<GenApi::IEnumeration *>(node);
00658 
00659         if (val != 0)
00660         {
00661           GenApi::IEnumEntry *entry=val->GetCurrentEntry();
00662 
00663           if (entry != 0)
00664           {
00665             ret=entry->GetSymbolic();
00666           }
00667           else if (exception)
00668           {
00669             throw std::invalid_argument(std::string("Current value is not defined: ")+name);
00670           }
00671         }
00672         else if (exception)
00673         {
00674           throw std::invalid_argument(std::string("Feature not enumeration: ")+name);
00675         }
00676       }
00677       else if (exception)
00678       {
00679         throw std::invalid_argument(std::string("Feature not readable: ")+name);
00680       }
00681     }
00682     else if (exception)
00683     {
00684       throw std::invalid_argument(std::string("Feature not found: ")+name);
00685     }
00686   }
00687   catch (const GENICAM_NAMESPACE::GenericException &ex)
00688   {
00689     if (exception)
00690     {
00691       throw std::invalid_argument(ex.what());
00692     }
00693   }
00694 
00695   return ret;
00696 }
00697 
00698 std::string getEnum(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
00699                     std::vector<std::string> &list, bool exception)
00700 {
00701   std::string ret;
00702 
00703   list.clear();
00704 
00705   try
00706   {
00707     GenApi::INode *node=nodemap->_GetNode(name);
00708 
00709     if (node != 0)
00710     {
00711       if (GenApi::IsReadable(node))
00712       {
00713         GenApi::IEnumeration *val=dynamic_cast<GenApi::IEnumeration *>(node);
00714 
00715         if (val != 0)
00716         {
00717           ret=val->GetCurrentEntry()->GetSymbolic();
00718 
00719           GenApi::StringList_t entry;
00720           val->GetSymbolics(entry);
00721 
00722           for (size_t i=0; i<entry.size(); i++)
00723           {
00724             list.push_back(std::string(entry[i]));
00725           }
00726         }
00727         else if (exception)
00728         {
00729           throw std::invalid_argument(std::string("Feature not enumeration: ")+name);
00730         }
00731       }
00732       else if (exception)
00733       {
00734         throw std::invalid_argument(std::string("Feature not readable: ")+name);
00735       }
00736     }
00737     else if (exception)
00738     {
00739       throw std::invalid_argument(std::string("Feature not found: ")+name);
00740     }
00741   }
00742   catch (const GENICAM_NAMESPACE::GenericException &ex)
00743   {
00744     if (exception)
00745     {
00746       throw std::invalid_argument(ex.what());
00747     }
00748   }
00749 
00750   return ret;
00751 }
00752 
00753 std::string getString(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
00754                       bool exception, bool igncache)
00755 {
00756   std::ostringstream out;
00757 
00758   try
00759   {
00760     GenApi::INode *node=nodemap->_GetNode(name);
00761 
00762     if (node != 0)
00763     {
00764       if (GenApi::IsReadable(node))
00765       {
00766         switch (node->GetPrincipalInterfaceType())
00767         {
00768           case GenApi::intfIBoolean:
00769             {
00770               GenApi::IBoolean *p=dynamic_cast<GenApi::IBoolean *>(node);
00771               out << p->GetValue(false, igncache);
00772             }
00773             break;
00774 
00775           case GenApi::intfIInteger:
00776             {
00777               GenApi::IInteger *p=dynamic_cast<GenApi::IInteger *>(node);
00778               int64_t value=p->GetValue(false, igncache);
00779 
00780               switch (p->GetRepresentation())
00781               {
00782                 case GenApi::HexNumber:
00783                   out << std::hex << value;
00784                   break;
00785 
00786                 case GenApi::IPV4Address:
00787                    out << ((value>>24)&0xff) << '.' << ((value>>16)&0xff) << '.'
00788                        << ((value>>8)&0xff) << '.' << (value&0xff);
00789                    break;
00790 
00791                 case GenApi::MACAddress:
00792                    out << std::hex << std::setfill('0');
00793                    out << std::setw(2) << ((value>>40)&0xff) << ':'
00794                        << std::setw(2) << ((value>>32)&0xff) << ':'
00795                        << std::setw(2) << ((value>>24)&0xff) << ':'
00796                        << std::setw(2) << ((value>>16)&0xff) << ':'
00797                        << std::setw(2) << ((value>>8)&0xff) << ':'
00798                        << std::setw(2) << (value&0xff);
00799                    break;
00800 
00801                 default:
00802                   out << value;
00803                   break;
00804               }
00805             }
00806             break;
00807 
00808           case GenApi::intfIFloat:
00809             {
00810               GenApi::IFloat *p=dynamic_cast<GenApi::IFloat *>(node);
00811               out << p->GetValue(false, igncache);
00812             }
00813             break;
00814 
00815           case GenApi::intfIEnumeration:
00816             {
00817               GenApi::IEnumeration *p=dynamic_cast<GenApi::IEnumeration *>(node);
00818               out << p->GetCurrentEntry()->GetSymbolic();
00819             }
00820             break;
00821 
00822           case GenApi::intfIString:
00823             {
00824               GenApi::IString *p=dynamic_cast<GenApi::IString *>(node);
00825               out << p->GetValue(false, igncache);
00826             }
00827             break;
00828 
00829           default:
00830             if (exception)
00831             {
00832               throw std::invalid_argument(std::string("Feature of unknown datatype: ")+name);
00833             }
00834             break;
00835         }
00836       }
00837       else if (exception)
00838       {
00839         throw std::invalid_argument(std::string("Feature not readable: ")+name);
00840       }
00841     }
00842     else if (exception)
00843     {
00844       throw std::invalid_argument(std::string("Feature not found: ")+name);
00845     }
00846   }
00847   catch (const GENICAM_NAMESPACE::GenericException &ex)
00848   {
00849     if (exception)
00850     {
00851       throw std::invalid_argument(ex.what());
00852     }
00853   }
00854 
00855   return out.str();
00856 }
00857 
00858 void checkFeature(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
00859                   const char *value, bool igncache)
00860 {
00861   std::string cvalue=rcg::getString(nodemap, name, true, igncache);
00862 
00863   if (cvalue != "" && cvalue != value)
00864   {
00865     std::ostringstream out;
00866     out << name << " == " << value << " expected: " << cvalue;
00867     throw std::invalid_argument(out.str());
00868   }
00869 }
00870 
00871 std::shared_ptr<GenApi::CChunkAdapter> getChunkAdapter(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
00872                                                        const std::string &tltype)
00873 {
00874   std::shared_ptr<GenApi::CChunkAdapter> chunkadapter;
00875 
00876   if (setBoolean(nodemap, "ChunkModeActive", true))
00877   {
00878     if (tltype == "GEV")
00879     {
00880       chunkadapter=std::shared_ptr<GenApi::CChunkAdapter>(new GenApi::CChunkAdapterGEV(nodemap->_Ptr));
00881     }
00882     else if (tltype == "U3V")
00883     {
00884       chunkadapter=std::shared_ptr<GenApi::CChunkAdapter>(new GenApi::CChunkAdapterU3V(nodemap->_Ptr));
00885     }
00886     else
00887     {
00888       chunkadapter=std::shared_ptr<GenApi::CChunkAdapter>(new GenApi::CChunkAdapterGeneric(nodemap->_Ptr));
00889     }
00890   }
00891 
00892   return chunkadapter;
00893 }
00894 
00895 std::string getComponetOfPart(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
00896                               const rcg::Buffer *buffer, uint32_t ipart)
00897 {
00898   std::string component;
00899 
00900   try
00901   {
00902     // get chunk component selector and proprietary chunk part index parmeters
00903 
00904     GenApi::IEnumeration *sel=dynamic_cast<GenApi::IEnumeration *>(nodemap->_GetNode("ChunkComponentSelector"));
00905     GenApi::IInteger *part=dynamic_cast<GenApi::IInteger *>(nodemap->_GetNode("ChunkPartIndex"));
00906 
00907     if (sel != 0 && part != 0)
00908     {
00909       if (GenApi::IsReadable(sel) && GenApi::IsWritable(sel) && GenApi::IsReadable(part))
00910       {
00911         // go through all available enumerations
00912 
00913         GenApi::NodeList_t list;
00914         sel->GetEntries(list);
00915 
00916         for (size_t i=0; i<list.size() && component.size() == 0; i++)
00917         {
00918           GenApi::IEnumEntry *entry=dynamic_cast<GenApi::IEnumEntry *>(list[i]);
00919 
00920           if (entry != 0 && GenApi::IsReadable(entry))
00921           {
00922             sel->SetIntValue(entry->GetValue());
00923 
00924             int64_t val=part->GetValue();
00925             if (val == ipart)
00926             {
00927               component=dynamic_cast<GenApi::IEnumEntry *>(list[i])->GetSymbolic();
00928             }
00929           }
00930         }
00931       }
00932     }
00933   }
00934   catch (const std::exception &)
00935   { /* ignore errors */ }
00936   catch (const GENICAM_NAMESPACE::GenericException &)
00937   { /* ignore errors */ }
00938 
00939   // try guessing component name from pixel format
00940 
00941   if (component.size() == 0 && buffer->getImagePresent(ipart))
00942   {
00943     switch (buffer->getPixelFormat(ipart))
00944     {
00945       case Mono8:
00946       case YCbCr411_8:
00947         if (buffer->getWidth(ipart) >= buffer->getHeight(ipart))
00948         {
00949           component="Intensity";
00950         }
00951         else
00952         {
00953           component="IntensityCombined";
00954         }
00955         break;
00956 
00957       case Coord3D_C16:
00958         component="Disparity";
00959         break;
00960 
00961       case Confidence8:
00962         component="Confidence";
00963         break;
00964 
00965       case Error8:
00966         component="Error";
00967         break;
00968 
00969       default:
00970         break;
00971     }
00972   }
00973 
00974   return component;
00975 }
00976 
00977 }


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 18:42:46