OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimCommon.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: David Burken
8 //
9 // Description: Common file for global functions.
10 //
11 //*************************************************************************
12 // $Id: ossimCommon.cpp 23141 2015-02-10 19:43:19Z dburken $
13 
14 #include <ossim/base/ossimCommon.h>
16 #include <ossim/base/ossimDpt.h>
17 #include <ossim/base/ossimDpt3d.h>
18 #include <ossim/base/ossimGpt.h>
19 #include <ossim/base/ossimIpt.h>
20 #include <ossim/base/ossimIrect.h>
24 #include <ossim/base/ossimString.h>
25 #include <ossim/base/ossimTrace.h>
26 #include <ossim/base/Thread.h>
27 #include <ossim/matrix/newmat.h>
28 #include <ctime>
29 #include <sstream>
30 #include <mutex>
31 
32 static std::mutex timeMutex;
33 static ossimTrace traceDebug("ossimCommon:debug");
34 
35 // stores a floating point nan value
36 const ossim::IntFloatBitCoercion ossim::nanValue(~ossim_int64(0));
37 
39 {
40  int c = in.peek();
41  while( !in.bad() && ossim::isWhiteSpace(c))
42  {
43  in.ignore();
44  c = in.peek();
45  }
46 
47  return in;
48 }
50 {
51  return ( (c == ' ') || (c == '\t') || (c == '\n')|| (c == '\r') ) ;
52 }
53 
55 {
56  union
57  {
58  short s;
59  char c[sizeof(short)];
60  } un;
61 
62  un.s = 0x0102;
63  if (un.c[0] == 2 && un.c[1] == 1)
64  {
65  return OSSIM_LITTLE_ENDIAN;
66  }
67  else
68  {
69  return OSSIM_BIG_ENDIAN;
70  }
71 }
72 
74 {
75  switch(scalarType)
76  {
77  case OSSIM_UINT8:
78  {
80  }
81  case OSSIM_SINT8:
82  {
84  }
85  case OSSIM_UINT16:
86  {
88  }
89  case OSSIM_SINT16:
90  {
92  }
93  case OSSIM_USHORT11:
94  {
96  }
97  case OSSIM_USHORT12:
98  {
100  }
101  case OSSIM_USHORT13:
102  {
104  }
105  case OSSIM_USHORT14:
106  {
108  }
109  case OSSIM_USHORT15:
110  {
112  }
113  case OSSIM_UINT32:
114  {
116  }
117  case OSSIM_SINT32:
118  {
120  }
121  case OSSIM_FLOAT32:
122  {
124  }
126  {
128  }
129  case OSSIM_FLOAT64:
130  {
132  }
134  {
136  }
138  default:
139  {
140  if(traceDebug())
141  {
143  << __FILE__ << ":" << __LINE__
144  << "\nUnhandled scalar type: " << scalarType << std::endl;
145  }
146  break;
147  }
148  }
149  return 0.0; // Should never happen...
150 }
151 
153 {
154  switch(scalarType)
155  {
156  case OSSIM_UINT8:
157  {
159  }
160  case OSSIM_SINT8:
161  {
163  }
164  case OSSIM_UINT16:
165  {
167  }
168  case OSSIM_SINT16:
169  {
171  }
172  case OSSIM_UINT11:
173  {
175  }
176  case OSSIM_UINT12:
177  {
179  }
180  case OSSIM_UINT13:
181  {
183  }
184  case OSSIM_UINT14:
185  {
187  }
188  case OSSIM_UINT15:
189  {
191  }
192  case OSSIM_UINT32:
193  {
195  }
196  case OSSIM_SINT32:
197  {
199  }
200  case OSSIM_FLOAT32:
201  {
203  }
205  {
207  }
208  case OSSIM_FLOAT64:
209  {
211  }
213  {
215  }
217  default:
218  {
219  if(traceDebug())
220  {
222  << __FILE__ << ":" << __LINE__
223  << "\nUnhandled scalar type: " << scalarType << std::endl;
224  }
225  break;
226  }
227  }
228  return 0.0; // Should never happen...
229 }
230 
232 {
233  switch(scalarType)
234  {
235  case OSSIM_UINT8:
236  {
238  }
239  case OSSIM_SINT8:
240  {
242  }
243  case OSSIM_UINT16:
244  {
246  }
247  case OSSIM_SINT16:
248  {
250  }
251  case OSSIM_UINT11:
252  {
254  }
255  case OSSIM_UINT12:
256  {
258  }
259  case OSSIM_UINT13:
260  {
262  }
263  case OSSIM_UINT14:
264  {
266  }
267  case OSSIM_UINT15:
268  {
270  }
271  case OSSIM_UINT32:
272  {
274  }
275  case OSSIM_SINT32:
276  {
278  }
279  case OSSIM_FLOAT32:
280  {
282  }
284  {
286  }
287  case OSSIM_FLOAT64:
288  {
290  }
292  {
294  }
296  default:
297  {
298  if(traceDebug())
299  {
301  << __FILE__ << ":" << __LINE__
302  << "\nUnhandled scalar type: " << scalarType << std::endl;
303  }
304  break;
305  }
306  }
307 
308  return 0.0; // Should never happen...
309 }
310 
312 {
313  switch(scalarType)
314  {
315  case OSSIM_UINT8:
316  {
317  return sizeof(ossim_uint8);
318  }
319  case OSSIM_SINT8:
320  {
321  return sizeof(ossim_sint8);
322  }
323  case OSSIM_UINT16:
324  case OSSIM_USHORT11:
325  case OSSIM_USHORT12:
326  case OSSIM_USHORT13:
327  case OSSIM_USHORT14:
328  case OSSIM_USHORT15:
329  {
330  return sizeof(ossim_uint16);
331  }
332  case OSSIM_SINT16:
333  {
334  return sizeof(ossim_sint16);
335  }
336  case OSSIM_UINT32:
337  {
338  return sizeof(ossim_uint32);
339  }
340  case OSSIM_SINT32:
341  {
342  return sizeof(ossim_sint32);
343  }
344  case OSSIM_FLOAT32:
346  {
347  return sizeof(ossim_float32);
348  }
349  case OSSIM_FLOAT64:
351  {
352  return sizeof(ossim_float64);
353  }
355  default:
356  {
357  if (traceDebug())
358  {
360  << __FILE__ << ":" << __LINE__
361  << "\nUnhandled scalar type: " << scalarType << std::endl;
362  }
363  break;
364  }
365  }
366 
367  return 1;
368 }
369 
371 {
372  bool result = false;
373  switch(scalarType)
374  {
375  case OSSIM_SINT8:
376  case OSSIM_SINT16:
377  case OSSIM_SINT32:
378  case OSSIM_FLOAT32:
379  case OSSIM_FLOAT64:
380  {
381  result = true;
382  break;
383  }
384  default:
385  {
386  break;
387  }
388  }
389  return result;
390 }
391 
393 {
394  ossim_uint32 actualBitsPerPixel = 0;
395  switch(scalarType)
396  {
397  case OSSIM_UINT8:
398  case OSSIM_SINT8:
399  {
400  actualBitsPerPixel = 8;
401  break;
402  }
403  case OSSIM_USHORT11:
404  {
405  actualBitsPerPixel = 11;
406  break;
407  }
408  case OSSIM_USHORT12:
409  {
410  actualBitsPerPixel = 12;
411  break;
412  }
413  case OSSIM_USHORT13:
414  {
415  actualBitsPerPixel = 13;
416  break;
417  }
418  case OSSIM_USHORT14:
419  {
420  actualBitsPerPixel = 14;
421  break;
422  }
423  case OSSIM_USHORT15:
424  {
425  actualBitsPerPixel = 15;
426  break;
427  }
428  case OSSIM_UINT16:
429  case OSSIM_SINT16:
430  {
431  actualBitsPerPixel = 16;
432  break;
433  }
434  case OSSIM_UINT32:
435  case OSSIM_SINT32:
436  case OSSIM_FLOAT32:
437  case OSSIM_CINT16:
439  {
440  actualBitsPerPixel = 32;
441  break;
442  }
443  case OSSIM_FLOAT64:
444  case OSSIM_CFLOAT32:
445  case OSSIM_CINT32:
447  {
448  actualBitsPerPixel = 64;
449  break;
450  }
451  case OSSIM_CFLOAT64:
452  {
453  actualBitsPerPixel = 128;
454 
455  break;
456  }
457  default:
458  {
459  if (traceDebug())
460  {
462  << __FILE__ << ":" << __LINE__
463  << "\nUnhandled scalar type: " << scalarType << std::endl;
464  }
465  break;
466  }
467  }
468  return actualBitsPerPixel;
469 }
470 
472 {
473  ossim_uint32 bitsPerPixel = 0;
474  switch(scalarType)
475  {
476  case OSSIM_UINT8:
477  case OSSIM_SINT8:
478  {
479  bitsPerPixel = 8;
480  break;
481  }
482  case OSSIM_USHORT11:
483  case OSSIM_USHORT12:
484  case OSSIM_USHORT13:
485  case OSSIM_USHORT14:
486  case OSSIM_USHORT15:
487  {
488  bitsPerPixel = 16;
489  break;
490  }
491  case OSSIM_UINT16:
492  case OSSIM_SINT16:
493  {
494  bitsPerPixel = 16;
495  break;
496  }
497  case OSSIM_UINT32:
498  case OSSIM_SINT32:
499  case OSSIM_FLOAT32:
501  {
502  bitsPerPixel = 32;
503  break;
504  }
505  case OSSIM_FLOAT64:
507  {
508  bitsPerPixel = 64;
509  break;
510  }
511  default:
512  {
513  if (traceDebug())
514  {
516  << __FILE__ << ":" << __LINE__
517  << "\nUnhandled scalar type: " << scalarType << std::endl;
518  }
519  break;
520  }
521  }
522  return bitsPerPixel;
523 }
524 
526 {
527  const char* tileSizeKw = ossimPreferences::instance()->
528  findPreference("tile_size");
529 
530  if(tileSizeKw)
531  {
532  std::vector<ossimString> splitArray;
533  ossimString tempString(tileSizeKw);
534  tempString.split(splitArray, " ");
535  bool hasX = true;
536  if(splitArray.size() == 2)
537  {
538  tileSize.x = splitArray[0].toInt32();
539  tileSize.y = splitArray[1].toInt32();
540  }
541  else if(splitArray.size() == 1)
542  {
543  tileSize.x = splitArray[0].toInt32();
544  tileSize.y = splitArray[0].toInt32();
545  }
546  else
547  {
548  tileSize = ossimIpt(0,0);
549  }
550  if(tileSize.x < 1)
551  {
552  tileSize.x = OSSIM_DEFAULT_TILE_WIDTH;
553  hasX = false;
554  }
555  if(tileSize.y < 1)
556  {
557  if(!hasX)
558  {
559  tileSize.y = OSSIM_DEFAULT_TILE_HEIGHT;
560  }
561  else
562  {
563  tileSize.y = tileSize.x;
564  }
565  }
566  }
567  else
568  {
569  tileSize.x = OSSIM_DEFAULT_TILE_WIDTH;
570  tileSize.y = OSSIM_DEFAULT_TILE_HEIGHT;
571  }
572 }
573 
574 std::string ossim::convertHtmlSpecialCharactersToNormalCharacter(const std::string& src)
575 {
576  ossimString result = src;
577  std::string::size_type pos = 0;
578  pos = result.find("&");
579 
580  while(pos != std::string::npos)
581  {
582  std::string::size_type size = result.size();
583  std::string test1(&result[pos], ossim::min(6, (int)(size-pos)));
584  std::string test2(&result[pos], ossim::min(5, (int)(size-pos)));
585  std::string test3(&result[pos], ossim::min(4, (int)(size-pos)));
586 
587  if(test1 == "&apos;")
588  {
589  result = result.substitute(test1, "'");
590  }
591  else if(test1 == "&quot;")
592  {
593  result = result.substitute(test1, "\"");
594  }
595  else if(test2 == "&amp;")
596  {
597  result = result.substitute(test2, "&");
598  }
599  else if(test3 == "&gt;")
600  {
601  result = result.substitute(test3, ">");
602  }
603  else if(test3 == "&lt;")
604  {
605  result = result.substitute(test3, "<");
606  }
607  pos = result.find("&", pos+1);
608  }
609 
610  return result;
611 }
612 
613 bool ossim::matrixToHpr( ossim_float64 hpr[3], const NEWMAT::Matrix& rotation )
614 {
615  //implementation converted from plib's sg.cxx
616  //PLIB - A Suite of Portable Game Libraries
617  //Copyright (C) 1998,2002 Steve Baker
618  //For further information visit http://plib.sourceforge.net
619 
620  NEWMAT::Matrix mat(rotation);
621 
622  ossimDpt3d col1(rotation[0][0], rotation[1][0], rotation[2][0]);
623  double s = col1.length();
624 
625  hpr[0] = 0.0;
626  hpr[1] = 0.0;
627  hpr[2] = 0.0;
628 
629  if ( s <= 0.00001 )
630  {
631  return true;
632  }
633 
634 
635  double oneOverS = 1.0f / s;
636  for( int i = 0; i < 3; i++ )
637  for( int j = 0; j < 3; j++ )
638  mat[i][j] = rotation[j][i] * oneOverS;
639 
640 
641  hpr[1] = ossim::asind(ossim::clamp(mat[1][2], -1.0, 1.0));
642 
643  double cp = ossim::cosd(hpr[1]);
644 
645  if ( cp > -0.00001 && cp < 0.00001 )
646  {
647  double cr = ossim::clamp(mat[0][1], -1.0, 1.0);
648  double sr = ossim::clamp(-mat[2][1], -1.0, 1.0);
649 
650  hpr[0] = 0.0f;
651  hpr[2] = ossim::atan2d(sr,cr);
652  }
653  else
654  {
655  cp = 1.0 / cp;
656  double sr = ossim::clamp((-mat[0][2] * cp), -1.0,1.0);
657  double cr = ossim::clamp((mat[2][2] * cp), -1.0, 1.0);
658  double sh = ossim::clamp((-mat[1][0] * cp), -1.0, 1.0);
659  double ch = ossim::clamp((mat[1][1] * cp), -1.0, 1.0);
660 
661  if ( (sh == 0.0f && ch == 0.0f) || (sr == 0.0f && cr == 0.0f) )
662  {
663  cr = ossim::clamp(mat[0][1], -1.0, 1.0);
664  sr = ossim::clamp(-mat[2][1], -1.0, 1.0);
665 
666  hpr[0] = 0.0f;
667  }
668  else
669  {
670  hpr[0] = ossim::atan2d(sh, ch);
671  }
672 
673  hpr[2] = ossim::atan2d(sr, cr);
674  }
675 
676  hpr[0] *= -1.0;
677  return true;
678 }
679 
681  const NEWMAT::Matrix& lsrMatrix,
682  const NEWMAT::Matrix& rotationalMatrix)
683 {
684  bool result = false;
685  NEWMAT::Matrix invertLsr(lsrMatrix.i());
686 
687  hpr[0] = 0.0;
688  hpr[1] = 0.0;
689  hpr[2] = 0.0;
690  result = matrixToHpr(hpr, invertLsr*rotationalMatrix);
691  if(std::abs(hpr[0]) < FLT_EPSILON)
692  {
693  hpr[0] = 0.0;
694  }
695  if(std::abs(hpr[1]) < FLT_EPSILON)
696  {
697  hpr[1] = 0.0;
698  }
699  if(std::abs(hpr[2]) < FLT_EPSILON)
700  {
701  hpr[2] = 0.0;
702  }
703 
704  return result;
705 }
706 
707 
708 void ossim::lexQuotedTokens(const std::string& str,
709  ossim_uint32 start,
710  const char* whitespace,
711  const char* quotes,
712  std::vector<std::string>& tokens,
713  bool& unbalancedQuotes)
714 {
715  ossimREQUIRE(whitespace != NULL);
716  ossimREQUIRE(quotes != NULL);
717  ossimREQUIRE(tokens != NULL);
718 
719  const char openQuote(quotes[0]), closeQuote(quotes[1]);
720 
721  tokens.clear();
722  unbalancedQuotes = false;
723 
724  int end=0;
725  while (start < str.length())
726  {
727  if (str[start] == openQuote)
728  {
729  int openBraceCount = 1;
730 
731  if (start+1 < str.length())
732  {
733  start++;
734  if (str[start] != closeQuote)
735  {
736  // end = start+1;
737  end = start;
738  while (static_cast<ossim_uint32>(end) < str.length() &&
739  openBraceCount > 0)
740  {
741  if (str[end] == openQuote)
742  openBraceCount++;
743  else if (str[end] == closeQuote)
744  openBraceCount--;
745  end++;
746  }
747  }
748  else
749  {
750  openBraceCount = 0;
751  start++;
752  end = start+1;
753  }
754  }
755  if (openBraceCount == 0)
756  {
757  tokens.push_back(str.substr(start, end-1-start));
758  }
759  else
760  {
761  unbalancedQuotes = true;
762  end = (int)str.length();
763  }
764  }
765  else if (str[start] == closeQuote)
766  {
767  unbalancedQuotes = true;
768  end = (int)str.length();
769 
770  }
771  else
772  {
773  end = (int)str.find_first_of(whitespace, start);
774  tokens.push_back(str.substr(start, end-start));
775  }
776 
777  start = (ossim_uint32)str.find_first_not_of(whitespace, end);
778  }
779 }
780 
781 void ossim::toStringList(ossimString& resultStringOfPoints,
782  const std::vector<ossimDpt>& pointList,
783  char separator)
784 {
785  ossim_uint32 idx = 0;
786  for(;idx < pointList.size();++idx)
787  {
788  ossimString pt = pointList[idx].toString();
789  if(resultStringOfPoints.empty())
790  {
791  resultStringOfPoints = pt;
792  }
793  else
794  {
795  resultStringOfPoints += (separator + pt);
796  }
797  }
798 }
799 
800 void ossim::toStringList(ossimString& resultStringOfPoints,
801  const std::vector<ossimIpt>& pointList,
802  char separator)
803 {
804  ossim_uint32 idx = 0;
805  for(;idx < pointList.size();++idx)
806  {
807  ossimString pt = pointList[idx].toString();
808  if(resultStringOfPoints.empty())
809  {
810  resultStringOfPoints = pt;
811  }
812  else
813  {
814  resultStringOfPoints += (separator + pt);
815  }
816  }
817 }
818 
819 void ossim::toStringList(ossimString& resultStringOfPoints,
820  const std::vector<ossimGpt>& pointList,
821  char separator)
822 {
823  ossim_uint32 idx = 0;
824  for(;idx < pointList.size();++idx)
825  {
826  ossimString pt = pointList[idx].toString();
827  if(resultStringOfPoints.empty())
828  {
829  resultStringOfPoints = pt;
830  }
831  else
832  {
833  resultStringOfPoints += (separator + pt);
834  }
835  }
836 }
837 
838 void ossim::toVector(std::vector<ossimDpt>& result,
839  const ossimString& stringOfPoints)
840 {
841  std::vector<ossimString> splitResult;
842 
843  // let grab each point string that is surrounded by ()
844  std::istringstream in(stringOfPoints.trim());
845  ossimString currentPoint = "";
846  ossimDpt tempPoint;
847  while(!in.bad()&&!in.eof())
848  {
849  skipws(in);
850  if(in.peek() == '(')
851  {
852  currentPoint += (char)in.get();
853  skipws(in);
854  if(in.peek() == '(') in.ignore();
855 
856  while(!in.bad()&&!in.eof()&&(in.peek() != ')'))
857  {
858  currentPoint += (char)in.get();
859  }
860  if(in.good())
861  {
862  currentPoint += (char)in.get();
863  tempPoint.toPoint(currentPoint);
864  result.push_back(tempPoint);
865  }
866  currentPoint = "";
867  }
868  else
869  {
870  in.ignore();
871  }
872  }
873 }
874 
875 void ossim::toVector(std::vector<ossimIpt>& result,
876  const ossimString& stringOfPoints)
877 {
878  std::vector<ossimString> splitResult;
879 
880  // let grab each point string that is surrounded by ()
881  std::istringstream in(stringOfPoints.trim());
882  ossimString currentPoint = "";
883  ossimIpt tempPoint;
884  while(!in.bad()&&!in.eof())
885  {
886  skipws(in);
887  if(in.peek() == '(')
888  {
889  currentPoint += (char)in.get();
890  skipws(in);
891  if(in.peek() == '(') in.ignore();
892 
893  while(!in.bad()&&!in.eof()&&(in.peek() != ')'))
894  {
895  currentPoint += (char)in.get();
896  }
897  if(in.good())
898  {
899  currentPoint += (char)in.get();
900  tempPoint.toPoint(currentPoint);
901  result.push_back(tempPoint);
902  }
903  currentPoint = "";
904  }
905  else
906  {
907  in.ignore();
908  }
909  }
910 }
911 void ossim::toVector(std::vector<ossimGpt>& result,
912  const ossimString& stringOfPoints)
913 {
914  std::vector<ossimString> splitResult;
915 
916  // let grab each point string that is surrounded by ()
917  std::istringstream in(stringOfPoints.trim());
918  ossimString currentPoint = "";
919  ossimGpt tempPoint;
920  while(!in.bad()&&!in.eof())
921  {
922  skipws(in);
923  if(in.peek() == '(')
924  {
925  currentPoint += (char)in.get();
926  skipws(in);
927  if(in.peek() == '(') in.ignore();
928 
929  while(!in.bad()&&!in.eof()&&(in.peek() != ')'))
930  {
931  currentPoint += (char)in.get();
932  }
933  if(in.good())
934  {
935  currentPoint += (char)in.get();
936  tempPoint.toPoint(currentPoint);
937  result.push_back(tempPoint);
938  }
939  currentPoint = "";
940  }
941  else
942  {
943  in.ignore();
944  }
945  }
946 }
947 
948 bool ossim::extractSimpleValues(std::vector<ossimString>& values,
949  const ossimString& stringOfPoints)
950 {
951  std::istringstream in(stringOfPoints);
952  ossim::skipws(in);
953  bool result = true;
954  if(stringOfPoints.empty()) return result;
955  char c = in.get();
956  ossimString value = "";
957  if(c == '(')
958  {
959  c = (char)in.get();
960  while((c!=')')&&
961  (in.good()))
962  {
963  if(c!= ',')
964  {
965  value += ossimString(c);
966  }
967  else
968  {
969  values.push_back(value);
970  value = "";
971  }
972  ossim::skipws(in);
973  c = in.get();
974  }
975  }
976  if(c!= ')')
977  {
978  result = false;
979  }
980  else
981  {
982  if(!value.empty())
983  {
984  values.push_back(value);
985  }
986  }
987 
988  return result;
989 }
990 
991 bool ossim::toSimpleVector(std::vector<ossim_uint32>& result,
992  const ossimString& stringOfPoints)
993 {
994  std::vector<ossimString> extractedValues;
995  bool resultFlag = extractSimpleValues(extractedValues, stringOfPoints);
996  if(resultFlag)
997  {
998  ossim_uint32 idx = 0;
999  ossim_uint32 size = (ossim_uint32) extractedValues.size();
1000  for(idx = 0; idx < size; ++idx)
1001  {
1002  result.push_back(extractedValues[idx].toUInt32());
1003  }
1004  }
1005  return resultFlag;
1006 }
1007 
1008 template <>
1010  const std::vector<ossim_uint8>& valuesList)
1011 
1012 {
1013  std::ostringstream out;
1014 
1015  if(!valuesList.empty())
1016  {
1017  ossim_uint32 idx = 0;
1018  ossim_uint32 size = (ossim_uint32)(valuesList.size()-1);
1019  for(idx = 0; idx < size; ++idx)
1020  {
1021  out << ((ossim_uint32)valuesList[idx]) << ",";
1022  }
1023  out << static_cast<ossim_uint32>(valuesList[size]);
1024  }
1025 
1026  result = "("+out.str()+")";
1027 }
1028 
1029 template <>
1031  const std::vector<ossim_float64>& valuesList)
1032 
1033 {
1034  std::ostringstream out;
1035  out << std::setiosflags(std::ios::fixed) << std::setprecision(20);
1036  if(!valuesList.empty())
1037  {
1038  ossim_uint32 idx = 0;
1039  ossim_uint32 size = (ossim_uint32) (valuesList.size()-1);
1040  for(idx = 0; idx < size; ++idx)
1041  {
1042  out << valuesList[idx] << ",";
1043  }
1044  out << valuesList[size];
1045  }
1046 
1047  result = "("+out.str()+")";
1048 }
1049 
1050 template <>
1052  const std::vector<ossim_float32>& valuesList)
1053 
1054 {
1055  std::ostringstream out;
1056  out << std::setiosflags(std::ios::fixed) << std::setprecision(20);
1057  if(!valuesList.empty())
1058  {
1059  ossim_uint32 idx = 0;
1060  ossim_uint32 size = (ossim_uint32) (valuesList.size()-1);
1061  for(idx = 0; idx < size; ++idx)
1062  {
1063  out << valuesList[idx] << ",";
1064  }
1065  out << valuesList[size];
1066  }
1067 
1068  result = "("+out.str()+")";
1069 }
1070 
1071 template <>
1073  const std::vector<ossimString>& valuesList)
1074 
1075 {
1076  std::ostringstream out;
1077  if(!valuesList.empty())
1078  {
1079  ossim_uint32 idx = 0;
1080  ossim_uint32 size = (ossim_uint32) (valuesList.size()-1);
1081  for(idx = 0; idx < size; ++idx)
1082  {
1083  out << valuesList[idx] << ",";
1084  }
1085  out << valuesList[size];
1086  }
1087 
1088  result = "("+out.str()+")";
1089 }
1090 
1091 bool ossim::toSimpleVector(std::vector<ossim_int32>& result,
1092  const ossimString& stringOfPoints)
1093 {
1094  std::vector<ossimString> extractedValues;
1095  bool resultFlag = extractSimpleValues(extractedValues, stringOfPoints);
1096  if(resultFlag)
1097  {
1098  ossim_uint32 idx = 0;
1099  ossim_uint32 size = (ossim_int32) extractedValues.size();
1100  for(idx = 0; idx < size; ++idx)
1101  {
1102  result.push_back(extractedValues[idx].toInt32());
1103  }
1104  }
1105  return resultFlag;
1106 }
1107 
1108 bool ossim::toSimpleVector(std::vector<ossim_uint16>& result,
1109  const ossimString& stringOfPoints)
1110 {
1111  std::vector<ossimString> extractedValues;
1112  bool resultFlag = extractSimpleValues(extractedValues, stringOfPoints);
1113  if(resultFlag)
1114  {
1115  ossim_uint32 idx = 0;
1116  ossim_uint32 size = (ossim_int32) extractedValues.size();
1117  for(idx = 0; idx < size; ++idx)
1118  {
1119  result.push_back(extractedValues[idx].toUInt32());
1120  }
1121  }
1122  return resultFlag;
1123 }
1124 
1125 bool ossim::toSimpleVector(std::vector<ossim_int16>& result,
1126  const ossimString& stringOfPoints)
1127 {
1128  std::vector<ossimString> extractedValues;
1129  bool resultFlag = extractSimpleValues(extractedValues, stringOfPoints);
1130  if(resultFlag)
1131  {
1132  ossim_uint32 idx = 0;
1133  ossim_uint32 size = (ossim_uint32) extractedValues.size();
1134  for(idx = 0; idx < size; ++idx)
1135  {
1136  result.push_back(extractedValues[idx].toInt32());
1137  }
1138  }
1139  return resultFlag;
1140 }
1141 
1142 bool ossim::toSimpleVector(std::vector<ossim_uint8>& result,
1143  const ossimString& stringOfPoints)
1144 {
1145  std::vector<ossimString> extractedValues;
1146  bool resultFlag = extractSimpleValues(extractedValues, stringOfPoints);
1147  if(resultFlag)
1148  {
1149  ossim_uint32 idx = 0;
1150  ossim_uint32 size = (ossim_uint32) extractedValues.size();
1151  for(idx = 0; idx < size; ++idx)
1152  {
1153  result.push_back(extractedValues[idx].toUInt8());
1154  }
1155  }
1156  return resultFlag;
1157 }
1158 
1159 bool ossim::toSimpleVector(std::vector<ossim_int8>& result,
1160  const ossimString& stringOfPoints)
1161 {
1162  std::vector<ossimString> extractedValues;
1163  bool resultFlag = extractSimpleValues(extractedValues, stringOfPoints);
1164  if(resultFlag)
1165  {
1166  ossim_uint32 idx = 0;
1167  ossim_uint32 size = (ossim_uint32) extractedValues.size();
1168  for(idx = 0; idx < size; ++idx)
1169  {
1170  result.push_back(extractedValues[idx].toUInt8());
1171  }
1172  }
1173  return resultFlag;
1174 }
1175 
1176 bool ossim::toSimpleVector(std::vector<ossimString>& result,
1177  const ossimString& stringOfStrings)
1178 {
1179  std::vector<ossimString> extractedValues;
1180  bool resultFlag = extractSimpleValues(result, stringOfStrings);
1181 
1182  return resultFlag;
1183 }
1184 
1186 {
1187  ossim_uint32 result;
1188  const char* str = ossimPreferences::instance()->findPreference("ossim_threads");
1189  if ( str )
1190  {
1191  result = ossimString(str).toUInt32();
1192  }
1193  else
1194  {
1195  result = static_cast<ossim_uint32>( ossim::Thread::getNumberOfProcessors() );
1196  }
1197  if ( !result )
1198  {
1199  result = 1;
1200  }
1201  return result;
1202 }
1203 
1205  const std::string& format, bool gmtFlag, std::string& result )
1206 {
1207  std::lock_guard<std::mutex> lock(timeMutex);
1208  time_t rawTime;
1209  time(&rawTime);
1210 
1211  struct tm* timeInfo;
1212  if ( gmtFlag )
1213  {
1214  timeInfo = gmtime(&rawTime);
1215  }
1216  else
1217  {
1218  timeInfo = localtime(&rawTime);
1219  }
1220 
1221  size_t size = 0;
1222  if ( timeInfo )
1223  {
1224  const size_t STRING_SIZE = 196; // This is a big time string size.
1225  char outStr[STRING_SIZE];
1226 
1227  size = strftime(outStr, STRING_SIZE, format.c_str(), timeInfo );
1228 
1229  if ( size )
1230  {
1231  // Per strftime spec not needed but null terminating anyway.
1232  outStr[STRING_SIZE-1] = '\0';
1233  result = outStr;
1234  }
1235  }
1236  if ( !size )
1237  {
1238  result.clear();
1239  }
1240 
1241 }
1242 
1244 {
1245  std::lock_guard<std::mutex> lock(timeMutex);
1246  time_t rawTime;
1247 
1248  time(&rawTime);
1249 
1250  return (ossim_int64)rawTime;
1251 }
1252 
1254 {
1255  ossim_uint32 result = 0;
1256  ossim_uint32 stopDimension = 0;
1257 
1258  // Get the stop dimension from ossim preferences.
1259  const char* lookup = ossimPreferences::instance()->
1261  if (lookup)
1262  {
1263  stopDimension = ossimString(lookup).toUInt32();
1264  }
1265 
1266  if (stopDimension == 0)
1267  {
1268  // Use the smallest default tile size.
1269  ossimIpt tileSize;
1270  ossim::defaultTileSize(tileSize);
1271  stopDimension = tileSize.x < tileSize.y ? tileSize.x : tileSize.y;
1272  }
1273 
1274  ossim_uint32 largestImageDimension =
1275  rect.width() > rect.height() ? rect.width() : rect.height();
1276 
1277  while(largestImageDimension > stopDimension)
1278  {
1279  largestImageDimension /= 2;
1280  ++result;
1281  }
1282 
1283  return result;
1284 }
16 bit unsigned integer (15 bits used)
8 bit signed integer
#define OSSIM_DEFAULT_MAX_PIX_UINT16
#define OSSIM_DEFAULT_NULL_PIX_UINT14
#define OSSIM_DEFAULT_MIN_PIX_UINT13
double asind(double x)
Definition: ossimCommon.h:265
ossimString substitute(const ossimString &searchKey, const ossimString &replacementValue, bool replaceAll=false) const
Substitutes searchKey string with replacementValue and returns a string.
OSSIM_DLL ossim_uint32 computeLevels(const ossimIrect &rect)
Computes the number of decimation levels to get to the overview stop dimension.
OSSIM_DLL ossim_int64 getTime()
Gets the current time.
16 bit unsigned integer (12 bits used)
#define OSSIM_DEFAULT_NULL_PIX_UINT16
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
32 bit complex floating point
64 bit floating point
T clamp(T x, T a, T b)
Definition: ossimCommon.h:168
16 bit unsigned integer
#define OSSIM_DEFAULT_MIN_PIX_UINT32
#define OSSIM_DEFAULT_MAX_PIX_DOUBLE
OSSIM_DLL void toStringList(ossimString &resultStringOfPoints, const std::vector< ossimDpt > &pointList, char separator=' ')
Will take a vector of ossimDpt and convert to a string list separated by spaces For example: (45...
#define OSSIM_DEFAULT_NULL_PIX_UINT13
16 bit unsigned integer (14 bits used)
#define OSSIM_DEFAULT_NULL_PIX_SINT16
float ossim_float32
#define OSSIM_DEFAULT_MIN_PIX_UINT11
ossim_uint32 height() const
Definition: ossimIrect.h:487
#define OSSIM_DEFAULT_MIN_PIX_UINT15
static ossimString toString(bool aValue)
Numeric to string methods.
OSSIM_DLL void defaultTileSize(ossimIpt &tileSize)
16 bit signed integer
void toSimpleStringList(ossimString &result, const std::vector< T > &valuesList)
This will output a vector of values inst a string.
Definition: ossimCommon.h:484
void split(std::vector< ossimString > &result, const ossimString &separatorList, bool skipBlankFields=false) const
Splits this string into a vector of strings (fields) using the delimiter list specified.
OSSIM_DLL ossimByteOrder byteOrder()
Definition: ossimCommon.cpp:54
16 bit unsigned integer (14 bits used)
OSSIM_DLL ossim_uint32 getActualBitsPerPixel(ossimScalarType scalarType)
Get actual bits per pixel for a given scalar type.
signed char ossim_sint8
ossim_uint32 toUInt32() const
16 bit unsigned integer (13 bits used)
16 bit unsigned integer (13 bits used)
#define OSSIM_DEFAULT_MIN_PIX_UINT16
32 bit floating point
unsigned short ossim_uint16
#define abs(a)
Definition: auxiliary.h:74
OSSIM_DLL bool extractSimpleValues(std::vector< ossimString > &values, const ossimString &stringOfPoints)
Generic function to extract a list of values into a vector of string where the string of points is of...
32 bit unsigned integer
#define OSSIM_DEFAULT_NULL_PIX_SINT8
OSSIM_DLL ossim_uint32 getNumberOfThreads()
Get the number threads to use from ossimPreferences or ossim::Thread.
#define OSSIM_DEFAULT_TILE_WIDTH
OSSIM_DLL std::string convertHtmlSpecialCharactersToNormalCharacter(const std::string &src)
bool toSimpleVector(std::vector< T > &result, const ossimString &stringOfPoints)
Definition: ossimCommon.h:537
#define OSSIM_DEFAULT_MAX_PIX_UINT32
#define OSSIM_DEFAULT_MAX_PIX_SINT8
double ossim_float64
#define OSSIM_DEFAULT_MIN_PIX_SINT32
#define OSSIM_DEFAULT_NULL_PIX_UINT32
OSSIM_DLL double defaultMin(ossimScalarType scalarType)
Definition: ossimCommon.cpp:73
OSSIM_DLL bool isSigned(ossimScalarType scalarType)
#define OSSIM_DEFAULT_NULL_PIX_DOUBLE
#define OSSIM_DEFAULT_MAX_PIX_UINT12
#define OSSIM_DEFAULT_MIN_PIX_SINT16
#define OSSIM_DEFAULT_MIN_PIX_DOUBLE
OSSIM_DLL std::istream & skipws(std::istream &in)
Definition: ossimCommon.cpp:38
const char * findPreference(const char *key) const
OSSIM_DLL void toVector(std::vector< ossimDpt > &result, const ossimString &stringOfPoints)
Will take a string list separated by spaces and convert to a vector of ossimDpts. ...
yy_size_t size
void toPoint(const std::string &s)
Initializes this point from string.
Definition: ossimGpt.cpp:116
signed short ossim_sint16
OSSIM_DLL void getFormattedTime(const std::string &format, bool gmtFlag, std::string &result)
Gets the current time.
std::string::size_type size() const
Definition: ossimString.h:405
#define FLT_EPSILON
#define OSSIM_DEFAULT_NULL_PIX_UINT15
32 bit signed integer
OSSIM_DLL double defaultNull(ossimScalarType scalarType)
#define OSSIM_DEFAULT_MAX_PIX_UINT15
unsigned int ossim_uint32
32 bit normalized floating point
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
void toPoint(const std::string &s)
Initializes this point from string.
Definition: ossimDpt.cpp:192
static ossim_uint64 getNumberOfProcessors()
Utility to return the number of processors (concurrent threads)
Definition: Thread.cpp:88
signed int ossim_sint32
#define OSSIM_DEFAULT_MAX_PIX_UINT13
#define OSSIM_DEFAULT_NULL_PIX_UINT11
double atan2d(double y, double x)
Definition: ossimCommon.h:267
#define OSSIM_DEFAULT_MIN_PIX_UINT14
OSSIM_DLL bool matrixToHpr(ossim_float64 hpr[3], const NEWMAT::Matrix &rotation)
Heading pitch roll extraction from a matrix.
OSSIM_DLL ossim_uint32 scalarSizeInBytes(ossimScalarType scalarType)
ossimByteOrder
T min(T a, T b)
Definition: ossimCommon.h:203
Class lets us see bit patterns of floats.
Definition: ossimCommon.h:104
ossim_uint32 width() const
Definition: ossimIrect.h:500
double cosd(double x)
Definition: ossimCommon.h:259
double length() const
Definition: ossimDpt3d.h:71
OSSIM_DLL void lexQuotedTokens(const std::string &str, ossim_uint32 start, const char *whitespace, const char *quotes, std::vector< std::string > &tokens, bool &unbalancedQuotes)
#define OSSIM_DEFAULT_MAX_PIX_SINT16
void toPoint(const std::string &s)
Initializes this point from string.
Definition: ossimIpt.cpp:170
static ossimPreferences * instance()
#define OSSIM_DEFAULT_NULL_PIX_NORM_FLOAT
ossimScalarType
OSSIM_DLL ossim_uint32 getBitsPerPixel(ossimScalarType scalarType)
Get bits per pixel for a given scalar type.
#define OSSIM_DEFAULT_MAX_PIX_FLOAT
16 bit complex integer
64 bit normalized floating point
16 bit unsigned integer (11 bits used)
16 bit unsigned integer (15 bits used)
#define OSSIM_DEFAULT_MIN_PIX_FLOAT
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
#define OSSIM_DEFAULT_MIN_PIX_NORM_DOUBLE
OSSIM_DLL double defaultMax(ossimScalarType scalarType)
#define OSSIM_DEFAULT_MAX_PIX_UINT14
ossim_int32 y
Definition: ossimIpt.h:142
#define OSSIM_DEFAULT_MIN_PIX_UINT12
#define OSSIM_DEFAULT_MIN_PIX_UINT8
#define OSSIM_DEFAULT_MAX_PIX_UINT11
#define OSSIM_DEFAULT_MIN_PIX_NORM_FLOAT
#define OSSIM_DEFAULT_TILE_HEIGHT
long long ossim_int64
bool empty() const
Definition: ossimString.h:411
#define OSSIM_DEFAULT_MAX_PIX_SINT32
#define OSSIM_DEFAULT_NULL_PIX_FLOAT
#define OSSIM_DEFAULT_MIN_PIX_SINT8
#define ossimREQUIRE(expr)
Definition: ossimCommon.h:19
ossim_int32 x
Definition: ossimIpt.h:141
64 bit complex floating point
8 bit unsigned integer
#define OSSIM_DEFAULT_MAX_PIX_UINT8
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
#define OSSIM_DEFAULT_NULL_PIX_UINT12
OSSIM_DLL bool isWhiteSpace(int c)
Definition: ossimCommon.cpp:49
#define OSSIM_DEFAULT_MAX_PIX_NORM_FLOAT
32 bit complex integer
static const char * OVERVIEW_STOP_DIMENSION_KW
#define OSSIM_DEFAULT_NULL_PIX_NORM_DOUBLE
16 bit unsigned integer (11 bits used)
#define OSSIM_DEFAULT_NULL_PIX_SINT32
unsigned char ossim_uint8
std::string::size_type find(const std::string &s, std::string::size_type pos=0) const
Searches for s as a substring of *this, beginning at character pos of *this.
Definition: ossimString.h:753
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
#define OSSIM_DEFAULT_MAX_PIX_NORM_DOUBLE
#define OSSIM_DEFAULT_NULL_PIX_UINT8
int ossim_int32
16 bit unsigned integer (12 bits used)