OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimAdjustableParameterInterface.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 // Author: Garrett Potts
7 //
8 //*************************************************************************
9 // $Id: ossimAdjustableParameterInterface.cpp 23297 2015-05-05 20:32:16Z dburken $
10 #include <algorithm>
14 
15 RTTI_DEF(ossimAdjustableParameterInterface, "ossimAdjustableParameterInterface");
16 
17 static const char* NUMBER_OF_ADJUSTMENTS_KW = "number_of_adjustments";
18 static const char* NUMBER_OF_ADJUSTMENTS_OLD_KW = "number_of_adjustements";
19 static const char* CURRENT_ADJUSTMENT_OLD_KW = "current_adjustement";
20 static const char* CURRENT_ADJUSTMENT_KW = "current_adjustment";
21 static const char* ADJUSTMENT_PREFIX = "adjustment_";
22 
24  :
25  theChangeFlags(false),
26  theAdjustmentList(0),
27  theCurrentAdjustment(0)
28 {
29 }
30 
32  :
33  theChangeFlags(rhs.theChangeFlags),
34  theAdjustmentList(rhs.theAdjustmentList),
35  theCurrentAdjustment(rhs.theCurrentAdjustment)
36 {
37 }
38 
40 {
42  if(numberOfParameters > 0)
43  {
44  theAdjustmentList[theAdjustmentList.size()-1].setNumberOfAdjustableParameters(numberOfParameters);
45  theAdjustmentList[theAdjustmentList.size()-1].setDescription("Initial adjustment");
46  }
47 
50 }
51 
53 {
54  if(!theAdjustmentList.size())
55  {
56  return;
57  }
58  theAdjustmentList[theCurrentAdjustment].setDescription(description);
59 }
60 
62 {
63  if(theAdjustmentList.size())
64  {
65  return theAdjustmentList[theCurrentAdjustment].getDescription();
66  }
67 
68  return "";
69 }
70 
71 
73 {
74  if(adjustmentIdx < theAdjustmentList.size())
75  {
76  return theAdjustmentList[adjustmentIdx].getDescription();
77  }
78  return "";
79 }
80 
82 {
83  if(adjustmentIdx < theAdjustmentList.size())
84  {
85  theCurrentAdjustment = adjustmentIdx;
87  if(notify)
88  {
90  }
91  }
92 }
93 
94 //*********************************************************************************
97 //*********************************************************************************
99 {
100  for (unsigned int i=0; i<theAdjustmentList.size(); i++)
101  {
102  if (theAdjustmentList[i].getDescription() == description)
103  {
104  setCurrentAdjustment(i, notify);
105  return true;
106  }
107  }
108  return false;
109 }
110 
112 {
113 }
114 
116 {
117  if(!theAdjustmentList.size())
118  {
119  return;
120  }
121 
122  ossim_uint32 saveCurrent = theCurrentAdjustment;
123  copyAdjustment();
125  ossim_uint32 numberOfAdjustables = getNumberOfAdjustableParameters();
126  ossim_uint32 idx = 0;
127 
128  for(idx = 0; idx < numberOfAdjustables; ++idx)
129  {
130  theAdjustmentList[saveCurrent].getParameterList()[idx].setParameter(theAdjustmentList[theAdjustmentList.size()-1].getParameterList()[idx].getParameter());
131  }
132 
133  setCurrentAdjustment(saveCurrent);
134 
136 
137  if(notify)
138  {
140  }
141 }
142 
144 {
145  if(!theAdjustmentList.size())
146  {
147  return;
148  }
149  if(idx < theAdjustmentList.size())
150  {
151  theAdjustmentList.push_back(theAdjustmentList[idx]);
152 
153  if(idx == theCurrentAdjustment)
154  {
156  initChangeFlags();
157  }
158  if(notify)
159  {
161  }
162  }
163 
164 }
165 
167 {
169 }
170 
172  bool createCopy)
173 {
174  if(!theAdjustmentList.size())
175  {
176  return;
177  }
178  if(idx < theAdjustmentList.size())
179  {
180  if(createCopy)
181  {
182  copyAdjustment(idx);
183  }
185  }
186 }
187 
189 {
191 }
192 
194 {
195  if (this != &rhs)
196  {
199  }
200  return *this;
201 }
202 
204 {
205  theAdjustmentList.clear();
207 }
208 
210 {
211  if(theAdjustmentList.size())
212  {
213  return theAdjustmentList[theCurrentAdjustment].getNumberOfAdjustableParameters();
214  }
215 
216  return 0;
217 }
218 
220 {
222 }
223 
225 {
226  if(!theAdjustmentList.size())
227  {
228  return;
229  }
230 
231  if(theCurrentAdjustment == idx)
232  {
235  {
236  if(theAdjustmentList.size() < 1)
237  {
239  }
240  else
241  {
243  }
244 
245  }
246 
247  if(notify)
248  {
250  }
251  }
252  else if(idx < theAdjustmentList.size())
253  {
254  theAdjustmentList.erase(theAdjustmentList.begin() + idx);
255  if(theAdjustmentList.size() < 1)
256  {
258  }
259  else
260  {
261  if(theCurrentAdjustment > idx)
262  {
264  if(notify)
265  {
267  }
268  }
269  }
270  if(notify)
271  {
273  }
274  }
275 }
276 
278 {
279  if(theAdjustmentList.size())
280  {
282  {
283  return theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].getParameter();
284  }
285  }
286 
287  return 0.0;
288 }
289 
290 void ossimAdjustableParameterInterface::setAdjustableParameter(ossim_uint32 idx, double value, double sigma, bool notify)
291 {
292  if(!theAdjustmentList.size())
293  {
294  return;
295  }
297  {
298  theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].setParameter(value);
299  theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].setSigma(sigma);
300  theChangeFlags[idx] = true;
301  if(notify)
302  {
304  }
305  }
306 
307 }
308 
310 {
311  if(!theAdjustmentList.size())
312  {
313  return;
314  }
316  {
317  theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].setParameter(value);
318  theChangeFlags[idx] = true;
319 
320  if(notify)
321  {
323  }
324  }
325 }
326 
328 {
329  if(theAdjustmentList.size())
330  {
332  {
333  return theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].getSigma();
334  }
335  }
336 
337  return 0.0;
338 }
339 
341 {
342  if(!theAdjustmentList.size())
343  {
344  return;
345  }
347  {
348  theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].setSigma(value);
349  if(notify)
350  {
352  }
353  }
354 }
355 
357 {
358  if(theAdjustmentList.size())
359  {
361  {
362  return theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].getUnit();
363  }
364  }
365 
366  return OSSIM_UNIT_UNKNOWN;
367 }
368 
370 {
371  if(theAdjustmentList.size())
372  {
374  {
375  theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].setUnit(unit);
376  }
377  }
378 }
379 
381 {
382  if(theAdjustmentList.size())
383  {
385  {
386  theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].setUnit((ossimUnitType)ossimUnitTypeLut::instance()->getEntryNumber(unit));
387  }
388  }
389 }
390 
391 
393 {
394  if(theAdjustmentList.size())
395  {
397  {
398  return theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].getDescription();
399  }
400  }
401 
402  return ossimString("");
403 }
404 
406  const ossimString& description)
407 {
408  if(!theAdjustmentList.size())
409  {
410  return;
411  }
413  {
414  theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].setDescription(description);
415  }
416 }
417 
419 {
420  if(!theAdjustmentList.size())
421  {
422  return;
423  }
424 
426  {
427  theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].setCenter(center);
428 
429  if(notify)
430  {
432  }
433  }
434 }
435 
437 {
438  if(!theAdjustmentList.size())
439  {
440  return 0.0;
441  }
443  {
444  return theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].getCenter();
445  }
446 
447  return 0.0;
448 }
449 
451 {
452  if(!theAdjustmentList.size())
453  {
454  return 0.0;
455  }
457  {
458  return theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].computeOffset();
459  }
460 
461  return 0.0;
462 }
463 
465  const ossimString& name)const
466 {
467  ossim_int32 result = -1;
468  if(adjustmentIdx < getNumberOfAdjustments())
469  {
470  ossim_uint32 idx = 0;
471  ossim_uint32 n = theAdjustmentList[adjustmentIdx].getNumberOfAdjustableParameters();
472  bool found = false;
473  for(idx = 0; ((idx < n)&&(!found)); ++idx)
474  {
475  if(theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].getDescription() == name)
476  {
477  result = (ossim_int32) idx;
478  }
479  }
480  }
481 
482  return result;
483 }
484 
486  const ossimString& name)const
487 {
488  ossim_int32 result = -1;
489  if(adjustmentIdx < getNumberOfAdjustments())
490  {
491  ossim_uint32 idx = 0;
492  ossim_uint32 n = theAdjustmentList[adjustmentIdx].getNumberOfAdjustableParameters();
493  bool found = false;
494  for(idx = 0; ((idx < n)&&(!found)); ++idx)
495  {
496  if(theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].getDescription().contains(name))
497  {
498  result = (ossim_int32) idx;
499  }
500  }
501  }
502 
503  return result;
504 }
505 
506 
508 {
509  if(!theAdjustmentList.size())
510  {
511  return false;
512  }
514  {
515  return theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].getLockFlag();
516  }
517 
518  return false;
519 
520 }
521 
523 {
524  if(!theAdjustmentList.size())
525  {
526  return;
527  }
529  {
530  theAdjustmentList[theCurrentAdjustment].getParameterList()[idxParam].setLockFlag(flag);
531  }
532 }
533 
535 {
536  if(!theAdjustmentList.size())
537  {
538  return false;
539  }
541  {
542  return theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].getLockFlag();
543  }
544 
545  return false;
546 }
547 
549 {
551 }
552 
554 {
556 }
557 
559 {
560  if(idxAdjustment < getNumberOfAdjustments())
561  {
562  ossim_uint32 idx = 0;
563  ossim_uint32 n = theAdjustmentList[theCurrentAdjustment].getNumberOfAdjustableParameters();
564 
565  for(idx = 0; idx < n; ++idx)
566  {
567  theAdjustmentList[idxAdjustment].getParameterList()[idx].setLockFlag(true);
568  }
569  }
570 }
571 
573 {
574  if(idxAdjustment < getNumberOfAdjustments())
575  {
576  ossim_uint32 idx = 0;
577  ossim_uint32 n = theAdjustmentList[theCurrentAdjustment].getNumberOfAdjustableParameters();
578 
579  for(idx = 0; idx < n; ++idx)
580  {
581  theAdjustmentList[idxAdjustment].getParameterList()[idx].setLockFlag(false);
582  }
583  }
584 }
585 
586 
588  ossim_float64 value,
589  bool notify)
590 {
591 // double center = getParameterCenter(idx);
592 // double sigma = getParameterSigma(idx);
593 // double minValue = center - sigma;
594 // double maxValue = center + sigma;
595 // double x = 0.0;
596 
597 // if(sigma != 0.0)
598 // {
599 // x = (value - center)/sigma;
600 
601 // value = center + x*sigma;
602 
603 // if(value < minValue)
604 // {
605 // x = -1;
606 // }
607 // else if(value >maxValue)
608 // {
609 // x = 1.0;
610 // }
611 // setAdjustableParameter(idx, x, false);
612 // }
613 
614  if(!theAdjustmentList.size())
615  {
616  return;
617  }
619  {
620  theAdjustmentList[theCurrentAdjustment].getParameterList()[idx].setOffset(value);
621  if(notify)
622  {
624  }
625  }
626 }
627 
629 {
630  if(!theAdjustmentList.size())
631  {
632  newAdjustment(numberOfParameters);
633  return;
634  }
635 
636  theAdjustmentList[theCurrentAdjustment].setNumberOfAdjustableParameters(numberOfParameters);
637 }
638 
640 {
641  setAdjustment(theCurrentAdjustment, adj, notify);
642 }
643 
645 {
646  if(idx < getNumberOfAdjustments())
647  {
648  theAdjustmentList[(int)idx] = adj;
649  if(notify)
650  {
652  }
653  }
654 }
655 
656 
658 {
659  theAdjustmentList.push_back(adj);
660  if(notify)
661  {
663  }
664 }
665 
667 {
669 }
670 
672 {
674 
675  if(idx < getNumberOfAdjustments())
676  {
677  adj = theAdjustmentList[(int)idx];
678  }
679 }
680 
682 {
683  return (ossim_uint32)theAdjustmentList.size();
684 }
685 
687 {
688  return theCurrentAdjustment;
689 }
690 
692 {
693  if(theAdjustmentList.size() > 0)
694  {
695  theAdjustmentList[theCurrentAdjustment].setDirtyFlag(flag);
696  }
697 }
698 
700 {
701  ossim_uint32 idx = 0;
702 
703  for(idx = 0; idx < theAdjustmentList.size(); ++idx)
704  {
705  theAdjustmentList[idx].setDirtyFlag(flag);
706  }
707 }
708 
710 {
711  ossim_uint32 idx = 0;
712 
713  for(idx = 0; idx < theAdjustmentList.size(); ++idx)
714  {
715  if(theAdjustmentList[idx].isDirty())
716  {
717  return true;
718  }
719  }
720 
721  return false;
722 }
723 
724 //*************************************************************************************************
726 //*************************************************************************************************
728  const ossimString& prefix)const
729 {
730  // Nothing to do if no adjustments defined (okramer 04Sep2005)
731  if (theAdjustmentList.size() == 0)
732  return true;
733 
734  // A problem: There may have been adjustments written to the KWL by another process that this
735  // instance doesn't know about. So we need to load in all adjustments present in the KWL and
736  // replace
737  kwl.add(prefix,
738  NUMBER_OF_ADJUSTMENTS_KW,
740  true);
741  kwl.add(prefix,
742  CURRENT_ADJUSTMENT_KW,
744  true);
745 
746  for(ossim_uint32 adjIdx = 0; adjIdx < theAdjustmentList.size(); ++adjIdx)
747  {
748  ossimString adjPrefix = prefix + (ossimString(ADJUSTMENT_PREFIX) + ossimString::toString(adjIdx)+".");
749 
750  theAdjustmentList[adjIdx].saveState(kwl,
751  adjPrefix);
752  }
753 
754  return true;
755 }
756 
757 //*************************************************************************************************
760 //*************************************************************************************************
762  const ossimString &prefix)
763 {
764  // Fetch current adjustment:
765  ossimAdjustmentInfo adjTosave;
766  getAdjustment(adjTosave);
767  ossimString currentLabel = adjTosave.getDescription();
768 
769  // Fetch the number of adjustments specified in the KWL:
770  int numberOfAdjustments = 0;
771  const char* value = kwl.find(prefix, NUMBER_OF_ADJUSTMENTS_KW);
772  if (value)
773  {
774  numberOfAdjustments = atoi(value);
775  }
776 
777  // Loop to read the descriptions of each adjustment in the KWL to see if a match exists. If
778  // we reach the end, insert it there:
779  // int saved_adj_idx;
780  ossimAdjustmentInfo adjInfo;
781  int i = 0;
782  while (true)
783  {
784  ossimString adjPrefix = prefix+(ossimString(ADJUSTMENT_PREFIX)+ossimString::toString(i)+".");
785  if (i < numberOfAdjustments)
786  {
787  adjInfo.loadState(kwl, adjPrefix);
788  }
789 
790  if ((i == numberOfAdjustments) || (adjInfo.getDescription() == currentLabel))
791  {
792  // match found or end of list, insert the new adjustment at this position:
793  adjTosave.saveState(kwl, adjPrefix);
794  // saved_adj_idx = i;
795 
796  // Need to bump the number of adjustments by one if we added a new one:
797  if (i == numberOfAdjustments)
798  {
799  kwl.add(prefix, NUMBER_OF_ADJUSTMENTS_KW, ++numberOfAdjustments);
800  }
801 
802  break;
803  }
804  ++i;
805  }
806 
808  //loadAdjustments(kwl, prefix);
809  //setCurrentAdjustment(saved_adj_idx);
810 }
811 
813  const ossimString& prefix)
814 {
815  theAdjustmentList.clear();
817 
818  const char* numberOfAdjustments = kwl.find(prefix, NUMBER_OF_ADJUSTMENTS_KW);
819  const char* currentAdjustment = kwl.find(prefix, CURRENT_ADJUSTMENT_KW);
820 
821  if(!numberOfAdjustments)
822  {
823  numberOfAdjustments = kwl.find(prefix, NUMBER_OF_ADJUSTMENTS_OLD_KW);
824  }
825  if(!currentAdjustment)
826  {
827  currentAdjustment = kwl.find(prefix, CURRENT_ADJUSTMENT_OLD_KW);
828  }
829  if(!numberOfAdjustments) return false;
830 
831  int maxdjustments = ossimString(numberOfAdjustments).toInt();
832 
833  for(int adjIdx = 0; adjIdx <maxdjustments; ++adjIdx)
834  {
835  ossimAdjustmentInfo info;
836  ossimString adjPrefix = prefix + (ossimString(ADJUSTMENT_PREFIX) + ossimString::toString(adjIdx)+".");
837 
838  if(!info.loadState(kwl, adjPrefix))
839  {
840  return false;
841  }
842  theAdjustmentList.push_back(info);
843  }
844 
845  theCurrentAdjustment = ossimString(currentAdjustment).toUInt32();
846  initChangeFlags();
847  return true;
848 }
849 
851 {
852 }
853 
854 
855 //*************************************************************************************************
857 //*************************************************************************************************
859 {
861  {
862  out <<"\nossimAdjustableParameterInterface base-class current adjustment index: "
863  << theCurrentAdjustment << "\n" << theAdjustmentList[theCurrentAdjustment] << std::ends;
864  }
865  else
866  {
867  out << "No adjustments specified." << std::endl;
868  }
869  return out;
870 }
871 
872 //*************************************************************************************************
875 //*************************************************************************************************
877 {
879  for (unsigned int i=0; i<num_params; ++i)
880  theChangeFlags[i] = areChanged;
881 }
882 
883 //*************************************************************************************************
885 //*************************************************************************************************
887 {
888  // Need to resize the flag list?
890  if (theChangeFlags.size() != num_params)
891  theChangeFlags.resize(num_params);
892  setAllChangeFlags(true);
893 }
894 
void setParameterDescription(ossim_uint32 idx, const ossimString &descrption)
bool saveAdjustments(ossimKeywordlist &kwl, const ossimString &prefix=ossimString("")) const
Save all adjustments to the KWL file.
void setCurrentAdjustment(ossim_uint32 adjustmentIndex, bool notify=false)
ossimUnitType
void setParameterLockFlag(ossim_uint32 idxParam, bool flag)
Represents serializable keyword/value map.
void keepAdjustment(ossim_uint32 idx, bool createCopy)
const char * find(const char *key) const
bool loadState(const ossimKeywordlist &kwl, const ossimString &prefix=ossimString(""))
static ossimString toString(bool aValue)
Numeric to string methods.
ossimString getDescription() const
void setAdjustmentDescription(const ossimString &description)
ossim_uint32 toUInt32() const
ossim_int32 findParameterIdxGivenDescription(ossim_uint32 adjustmentIdx, const ossimString &name) const
ossimString getParameterDescription(ossim_uint32 idx) const
void setAdjustment(const ossimAdjustmentInfo &adj, bool notify=false)
double ossim_float64
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
ossimUnitType getParameterUnit(ossim_uint32 idx) const
void setParameterOffset(ossim_uint32 idx, ossim_float64 value, bool notify=false)
virtual void saveCurrentAdjustmentOnly(ossimKeywordlist &kwl, const ossimString &prefix=ossimString(""))
Saves the current active adjustment to the KWL file.
os2<< "> n<< " > nendobj n
bool saveState(ossimKeywordlist &kwl, const ossimString &prefix=ossimString("")) const
void newAdjustment(ossim_uint32 numberOfParameters=0)
unsigned int ossim_uint32
void setAllChangeFlags(bool areChanged)
Sets all the change flags to the boolean indicated to indicate parameters are changed (TRUE) or not (...
void addAdjustment(const ossimAdjustmentInfo &adj, bool notify)
bool loadAdjustments(const ossimKeywordlist &kwl, const ossimString &prefix=ossimString(""))
void unlockAllParameters(ossim_uint32 idxAdjustment)
void setParameterUnit(ossim_uint32 idx, ossimUnitType unit)
void lockAllParameters(ossim_uint32 idxAdjustment)
virtual void setAdjustableParameter(ossim_uint32 idx, double value, bool notify=false)
void resizeAdjustableParameterArray(ossim_uint32 numberOfParameters)
std::ostream & print(std::ostream &out) const
Dumps the currently active adjustment to ostream.
RTTI_DEF(ossimAdjustableParameterInterface, "ossimAdjustableParameterInterface")
const ossimAdjustableParameterInterface & operator=(const ossimAdjustableParameterInterface &rhs)
void getAdjustment(ossimAdjustmentInfo &adj) const
std::vector< ossimAdjustmentInfo > theAdjustmentList
void setNumberOfAdjustableParameters(ossim_uint32 numberOfAdjustableParameters)
ossim_int32 findParameterIdxContainingDescription(ossim_uint32 adjustmentIdx, const ossimString &name) const
void setParameterCenter(ossim_uint32 idx, double center, bool notify=false)
static ossimUnitTypeLut * instance()
Returns the static instance of an ossimUnitTypeLut object.
void initChangeFlags()
Initializes the change flags to TRUE.
void setParameterSigma(ossim_uint32 idx, double value, bool notify=false)
int toInt() const
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
void copyAdjustment(ossim_uint32 idx, bool notify)
int ossim_int32
const char * getDescription()