OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimVertexExtractor.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: David Burken
6 // TR # 136 kminear Fix extractVertices method
7 //
8 //*************************************************************************
9 // $Id: ossimVertexExtractor.cpp 21184 2012-06-29 15:13:09Z dburken $
10 
11 #include <fstream>
12 using namespace std;
13 
17 #include <ossim/base/ossimTrace.h>
19 
20 static ossimTrace traceDebug("ossimVertexExtractor:debug");
21 
22 RTTI_DEF2(ossimVertexExtractor, "ossimVertexExtractor",
24 
26  :
27  ossimOutputSource(0, // owner
28  1,
29  0,
30  true,
31  true),
33  theAreaOfInterest(),
34  theFilename(ossimFilename::NIL),
35  theFileStream(),
36  theVertice(4),
37  theLeftEdge(0),
38  theRightEdge(0)
39 {
40  if (inputSource == 0)
41  {
42  ossimNotify(ossimNotifyLevel_WARN) << "ossimVertexExtractor::ossimVertexExtractor ERROR"
43  << "\nNULL input image source passed to constructor!"
44  << std::endl;
45  }
46 
47  connectMyInputTo(0, inputSource);
48 // theInputObjectList[0] = inputSource;
50 }
51 
53 {
54  if (theLeftEdge)
55  {
56  delete [] theLeftEdge;
57  theLeftEdge = 0;
58  }
59  if (theRightEdge)
60  {
61  delete [] theRightEdge;
62  theRightEdge = 0;
63  }
64 }
65 
67 {
68  static const char MODULE[] = "ossimVertexExtractor::execute";
69 
70  if (traceDebug()) CLOG << " Entered..." << endl;
71 
73  {
74  ossimNotify(ossimNotifyLevel_WARN) << "ossimVertexExtractor::execute WARNING:"
75  << "\nOutput file name is empty. Use setFilename method..."
76  << std::endl;
77  return false;
78  }
79 
81  {
82  ossimNotify(ossimNotifyLevel_NOTICE) << MODULE << " NOTICE ossimVertexExtractor::execute:"
83  << "\nArea of interest is not set. Use setAreaOfInterest method..."
84  << "\nDefaulting to bounding rectangle of input source."
85  << std::endl;
86  ossimImageSource* src = reinterpret_cast<ossimImageSource*>(getInput(0));
88  }
89 
91 
92  if (scanForEdges())
93  {
94  if (extractVertices())
95  {
96  writeVertices();
97  }
98  else
99  {
100  return false;
101  }
102  }
103  else
104  {
105  return false;
106  }
107 
109 
110  if (traceDebug()) CLOG << " Exited..." << endl;
111 
112  return true;
113 }
114 
116 {
117  static const char MODULE[] = "ossimVertexExtractor::scanForEdges";
118 
119  if (traceDebug()) CLOG << " Entered..." << endl;
120 
121  ossimImageSource* src = reinterpret_cast<ossimImageSource*>(getInput(0));
122  if (!src)
123  {
125  << "WARN ossimVertexExtractor::scanForEdges():"
126  << "\nInput source is null. Returning..." << std::endl;
127  return false;
128  }
129 
130  // Allocate the arrays to hold the edges.
131  if (theLeftEdge) delete [] theLeftEdge;
132  if (theRightEdge) delete [] theRightEdge;
135  for (ossim_int32 i=0; i<(int)theAreaOfInterest.height(); ++i)
136  {
139  }
140 
141  // Some constants needed throughout...
142  const ossim_int32 TILE_HEIGHT = src->getTileHeight();
143  const ossim_int32 TILE_WIDTH = src->getTileWidth();
144  const ossim_int32 START_LINE = theAreaOfInterest.ul().y;
145  const ossim_int32 STOP_LINE = theAreaOfInterest.lr().y;
146  const ossim_int32 START_SAMP = theAreaOfInterest.ul().x;
147  const ossim_int32 STOP_SAMP = theAreaOfInterest.lr().x;
148 
149  // For percent complete status.
150  double total_tiles_y_dir = theAreaOfInterest.height() / TILE_HEIGHT;
151  if (theAreaOfInterest.height() % TILE_HEIGHT) total_tiles_y_dir += 1.0;
152  double tiles_processed = 0.0;
153 
154  // Set the status message to be "scanning source for edges..."
155  ossimNotify(ossimNotifyLevel_INFO) << "Scanning image source for edges..." << std::endl;
156 
157  // Start off with a percent complete at 0...
158  setPercentComplete(0.0);
159 
160  // Start of loop to get the left edges.
161 
162  // Tile loop in line direction through area of interest.
163 
164  for (ossim_int32 line = START_LINE; line < STOP_LINE; line += TILE_HEIGHT)
165  {
166  const ossim_int32 START_INDEX = line - START_LINE;
167  const ossim_int32 STOP_INDEX = ( (line+TILE_HEIGHT-1) < STOP_LINE ) ?
168  (START_INDEX+TILE_HEIGHT-1) :
170  const ossim_int32 TILE_LINE_STOP = ((line+TILE_HEIGHT-1) < STOP_LINE) ?
171  (line+TILE_HEIGHT-1) : STOP_LINE;
172 
173  // See if all the edges have been found for these tile lines.
174  bool all_edges_found = true;
175  for (ossim_int32 i = START_INDEX; i <= STOP_INDEX; ++i)
176  {
177  if (theLeftEdge[i] == OSSIM_INT_NAN)
178  {
179  all_edges_found = false;
180  break;
181  }
182  }
183 
184  // Extract the left edges...
185  if (all_edges_found == false)
186  {
187  //***
188  // Tile loop in sample direction through area of interest
189  // (left edges).
190  //***
191  for (ossim_int32 samp = START_SAMP; samp < STOP_SAMP; samp += TILE_WIDTH)
192  {
193  // Get the tile.
195  src->getTile(ossimIpt(samp, line));
196 
197  if (!id.valid() || id->getDataObjectStatus() == OSSIM_NULL ||
198  id->getDataObjectStatus() == OSSIM_EMPTY)
199  {
200  continue; // Nothing to do...
201  }
202 
203  // Line loop through tile.
204  const ossim_int32 TILE_SAMP_STOP = ((samp+TILE_WIDTH-1) < STOP_SAMP) ?
205  (samp+TILE_WIDTH-1) : STOP_SAMP;
206 
207  for (ossim_int32 y = line; y <= TILE_LINE_STOP; ++y)
208  {
209  ossim_int32 edge_index = y - START_LINE;
210  if (theLeftEdge[edge_index] == OSSIM_INT_NAN)
211  {
212  for (ossim_int32 x = samp; x <= TILE_SAMP_STOP; ++x)
213  {
214  if (! (id->isNull(ossimIpt(x,y))))
215  {
216  // Capture the first valid pixel.
217  theLeftEdge[edge_index] = x - START_SAMP;
218  break;
219  }
220  }
221  }
222  }
223  } // End of tile loop in sample direction through area of interest.
224  } // End of (all_lines_checked == false) (left edges)
225 
226  // See if all the right edges have been found for these tile lines.
227  all_edges_found = true;
228  for (ossim_int32 i = START_INDEX; i <= STOP_INDEX; ++i)
229  {
230  if (theRightEdge[i] == OSSIM_INT_NAN)
231  {
232  all_edges_found = false;
233  break;
234  }
235  }
236 
237  // Extract the right edges...
238  if (all_edges_found == false)
239  {
240  //***
241  // Tile loop in sample direction through area of interest
242  // (right edges).
243  //***
244 
245  // Get the x origin of the last tile in a row.
246  const ossim_int32 END_TILE_X = START_SAMP + ((theAreaOfInterest.width()/
247  TILE_WIDTH)*TILE_WIDTH);
248 
249 
250  for (ossim_int32 samp = END_TILE_X; samp >= START_SAMP; samp -= TILE_WIDTH)
251  {
252  // Get the tile.
254  src->getTile(ossimIpt(samp, line));
255 
256  if (!id.valid() || id->getDataObjectStatus() == OSSIM_NULL ||
257  id->getDataObjectStatus() == OSSIM_EMPTY)
258  {
259  continue; // Nothing to do...
260  }
261 
262  // Line loop through tile.
263  const ossim_int32 TILE_SAMP_STOP = ((samp+TILE_WIDTH-1) < STOP_SAMP) ?
264  (samp+TILE_WIDTH-1) : STOP_SAMP;
265 
266  for (ossim_int32 y = line; y <= TILE_LINE_STOP; ++y)
267  {
268  ossim_int32 edge_index = y - START_LINE;
269  if (theRightEdge[edge_index] == OSSIM_INT_NAN)
270  {
271  for (ossim_int32 x = TILE_SAMP_STOP; x >= samp; --x)
272  {
273  if (! (id->isNull(ossimIpt(x,y))))
274  {
275  // Capture the first valid pixel.
276  theRightEdge[edge_index] = x - START_SAMP;
277  break;
278  }
279  }
280  }
281  }
282 
283  } // End of tile loop in sample direction through area of interest.
284 
285  } // End of (all_lines_checked == false)
286 
287  // Set the percent complete.
288  tiles_processed += 1.0;
289  setPercentComplete(tiles_processed/total_tiles_y_dir*100.0);
290  } // End of loop through tiles in line direction.
291 
292  setPercentComplete(100.0);
293 
294  if (traceDebug())
295  {
296  CLOG << "DEBUG:" << endl;
297  for (ossim_int32 i=0; i<(int)theAreaOfInterest.height(); ++i)
298  {
299  ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG: left[" << i << "]: "
300  << theLeftEdge[i]
301  << " right[" << i << "]: "
302  << theRightEdge[i]
303  << std::endl;
304  }
305  }
306 
307 
308  return true;
309 }
310 
312 {
313  //***
314  // This method returns the non-null vertexes of the image corners.
315  // This can be used to initialize the "ValidImageVertices" for an
316  // image.
317  // This method does not handle images that have more than four vertexes.
318  //***
319  static const char MODULE[] = "ossimVertexExtractor::extractVertices";
320 
321  if (traceDebug()) CLOG << " Entered..." << endl;
322 
323  if (!theLeftEdge || !theRightEdge)
324  {
325  ossimNotify(ossimNotifyLevel_WARN) << "ERROR ossimVertexExtractor::extractVertices():"
326  << "\nEdges not initialized!" << std::endl;
327  return false;
328  }
329 
330  // Image must be quadrilateral (i.e. 4 sided polygon)
331 
332  ossim_int32 total_lines = theAreaOfInterest.height();
333 
334  ossim_int32 topLine = 0;
335  ossim_int32 bottomLine = 0;
336 
337  ossim_int32 firstLeftSample = 0;
338  ossim_int32 firstRightSample = 0;
339 
340  ossim_int32 lastLeftSample = 0;
341  ossim_int32 lastRightSample = 0;
342 
343  ossim_int32 leftMostSample = 0;
344  ossim_int32 leftMostSampleLine = 0;
345 
346  ossim_int32 rightMostSample = 0;
347  ossim_int32 rightMostSampleLine = 0;
348 
349  ossim_int32 leftCorner_A = 0;
350  ossim_int32 leftCornerLine_A = 0;
351  ossim_int32 leftCorner_B = 0;
352  ossim_int32 leftCornerLine_B = 0;
353 
354  ossim_int32 rightCorner_A = 0;
355  ossim_int32 rightCornerLine_A = 0;
356  ossim_int32 rightCorner_B = 0;
357  ossim_int32 rightCornerLine_B = 0;
358 
359 
360  bool found_first_non_null_line = 0;
361  bool found_last_non_null_line = 0;
362 
363  bool rhombus = false;
364  bool square = false;
365  bool left = false;
366  bool right = false;
367 
368  ossim_int32 first_non_null_line = 0;
369  ossim_int32 last_non_null_line = 0;
370 
371  ossim_int32 i = 0;
372  while(found_last_non_null_line == 0)
373  {
374  // Look for the first row with a valid DN
375  // Nulls are negative
376 
377  if( (theLeftEdge[i] >= 0)
378  && (found_first_non_null_line == 0) )
379  {
380  // Found first valid pixel at row i
381  found_first_non_null_line = 1;
382  first_non_null_line = i;
383 
384  // Finish walking down the rows of the image
385  while( (found_first_non_null_line == 1)
386  && (theLeftEdge[i] >= 0)
387  && (found_last_non_null_line == 0)
388  && (i <= total_lines) )
389  {
390  i = i+1;
391  }
392  found_last_non_null_line = 1;
393  last_non_null_line = i-1;
394  }
395 
396  i = i+1;
397 
398  }//end while "found_last_non_null_line == 0"
399 
400  last_non_null_line = last_non_null_line -1;
401 
402  topLine = first_non_null_line;
403  bottomLine = last_non_null_line;
404 
405  // Record the slope searching from the right edge
406  ossim_int32 k = 0;
407  ossim_int32 start = first_non_null_line;
408  ossim_int32 end = last_non_null_line;
409  ossim_int32 sizeDeltaSlope = last_non_null_line - first_non_null_line;
410  double* rightSlope = new double[sizeDeltaSlope];
411 
412  for(ossim_int32 i = start; i <= (end - 100); i += 100)
413  {
414  ossim_int32 run = theRightEdge[i] - theRightEdge[i + 100];
415  if(run != 0)
416  {
417  rightSlope[k] = 100.0 / run;
418  }
419  else
420  {
421  rightSlope[k]= OSSIM_INT_NAN;
422  }
423 
424  k = k + 1;
425  }
426  if (traceDebug())
427  {
428  CLOG << "DEBUG:" << endl;
429  for (ossim_int32 i=0; i<= k-1; i++)
430  {
431  ossimNotify(ossimNotifyLevel_DEBUG)<< setprecision(15) << "rightSlope[" << i << "]: "
432  << rightSlope[i]
433  << std::endl;
434  }
435  }
436 
437  // Record the slope searching from the left edge
438  k = 0;
439  double* leftSlope = new double[sizeDeltaSlope];
440 
441  for(ossim_int32 i = start; i <= (end - 100); i += 100)
442  {
443  ossim_int32 run = theLeftEdge[i] - theLeftEdge[i + 100];
444  if(run != 0)
445  {
446  leftSlope[k] = 100.0 / run;
447  }
448  else
449  {
450  leftSlope[k] = OSSIM_INT_NAN;
451  }
452 
453  k = k + 1;
454  }
455  if (traceDebug())
456  {
457  CLOG << "DEBUG:" << endl;
458  for (ossim_int32 i=0; i<= k-1; i++)
459  {
460  ossimNotify(ossimNotifyLevel_DEBUG) << setprecision(15) << "leftSlope[" << i << "]: "
461  << leftSlope[i]
462  << std::endl;
463  }
464  }
465  ossim_int32 sizeOftheSlope = k-1;
466  ossim_int32 counter = 0;
467 
468 
469  // Find the right most sample
470  ossim_int32 rightMostEdgeTemp = theRightEdge[topLine];
471  ossim_int32 rightMostEdgeTempLine = 0;
472 
473  for(ossim_int32 i= (topLine+1); i<bottomLine; i++)
474  {
475  if(theRightEdge[i] >= rightMostEdgeTemp)
476  {
477  rightMostEdgeTemp = theRightEdge[i];
478  rightMostEdgeTempLine = i;
479  }
480  }
481  rightMostSample = rightMostEdgeTemp;
482  rightMostSampleLine = rightMostEdgeTempLine-1;
483  lastLeftSample = theLeftEdge[bottomLine];
484 
485  // Find the left most sample
486  ossim_int32 leftMostEdgeTemp = theLeftEdge[topLine];
487  ossim_int32 leftMostEdgeTempLine = 0;
488 
489  for(ossim_int32 i= (topLine+1); i<bottomLine; i++)
490  {
491  if(theLeftEdge[i] <= leftMostEdgeTemp)
492  {
493  leftMostEdgeTemp = theLeftEdge[i];
494  leftMostEdgeTempLine = i;
495  }
496  }
497  leftMostSample = leftMostEdgeTemp;
498  leftMostSampleLine = leftMostEdgeTempLine-1;
499  firstLeftSample = theLeftEdge[topLine];
500 
501  // Case: Check for square
502  for(ossim_int32 i=0; i < sizeOftheSlope; ++i)
503  {
504  if(leftSlope[i]==rightSlope[i])
505  {
506  counter = counter + 1;
507  }
508  }
509 
510  if(counter == sizeOftheSlope)
511  {
512  if (traceDebug())
513  {
514  ossimNotify(ossimNotifyLevel_DEBUG)<<"\n\n***Case = SQUARE***"<<endl<<endl;
515  }
516 
517  square = 1;
518 
519  leftCornerLine_A = topLine;
520  //leftCorner_A = theLeftEdge[topLine]; //0
521  leftCorner_A = leftMostSample;
522 
523  rightCornerLine_A = topLine;
524  //rightCorner_A = theRightEdge[topLine]; //1
525  rightCorner_A = rightMostSample; //1
526 
527  rightCornerLine_B = bottomLine;
528  //rightCorner_B = theRightEdge[bottomLine]; //2
529  rightCorner_B = rightMostSample;
530 
531  leftCornerLine_B = bottomLine;
532  //leftCorner_B = theLeftEdge[bottomLine]; //3
533  leftCorner_B = leftMostSample;
534  }
535 
536  firstRightSample = theRightEdge[topLine];
537  lastRightSample = theRightEdge[bottomLine];
538 
539 
540 
541  ossim_int32 halfsamps = (rightMostSample - leftMostSample ) / 2;
542 
543  if(square == 0)
544  {
545  if( (firstRightSample - firstLeftSample) > halfsamps )
546  {
547  // Case is rhombus (clipped or not clipped)
548 
549  rhombus = 1;
550  if (traceDebug())
551  {
552  ossimNotify(ossimNotifyLevel_DEBUG)<<"\n\n***Case = RHOMBUS***"<<endl;
553  ossimNotify(ossimNotifyLevel_DEBUG)<<"here"<<endl;
554  }
555 
556  leftCornerLine_A = topLine;
557  leftCorner_A = firstLeftSample; //0
558 
559  rightCornerLine_A = topLine;
560  rightCorner_A= firstRightSample; //1
561 
562  rightCornerLine_B = bottomLine;
563  rightCorner_B = lastRightSample; //2
564 
565  leftCornerLine_B = bottomLine;
566  leftCorner_B = lastLeftSample; //3
567 
568  }
569  }
570 
571 
572  if(square == 0 && rhombus == 0)
573  {//if not square or rhombus
574 
575  if(firstLeftSample < lastLeftSample)
576  {//if tilted right
577 
578  if (traceDebug())
579  {
580  ossimNotify(ossimNotifyLevel_DEBUG)<<"\n\n***Case = TILTED RIGHT***"<<endl<<endl;
581  }
582 
583  right = true;
584 
585  // Regression line 2 is the right side
586  // Regression line 4 is the left side
587  // These are handled differently
588  // These sides may be 'uneven' or 'torn' or 'louvered'
589  // This code finds the best regression line that 'cuts off'
590  // this edge fringe
591 
592  //Regression Line 1
593 
594  ossim_int32 line1_pt4 = rightMostSampleLine;
595  ossim_int32 line1_pt0 = topLine;
596  ossim_int32 line1_pt2 = (line1_pt0 + line1_pt4)/2;
597  ossim_int32 line1_pt1 = (line1_pt2 + line1_pt0)/2;
598  ossim_int32 line1_pt3 = (line1_pt2 + line1_pt4)/2;
599 
600  double line1RegPtsSamples[] = { static_cast<double>(theRightEdge[line1_pt1]),
601  static_cast<double>(theRightEdge[line1_pt2]),
602  static_cast<double>(theRightEdge[line1_pt3]) };
603  double line1RegPtsLines[] = { static_cast<double>(-line1_pt1),
604  static_cast<double>(-line1_pt2),
605  static_cast<double>(-line1_pt3) };
606 
607  double sum_xy_line1 = 0.0;
608  double sum_x_line1 = 0.0;
609  double sum_y_line1 = 0.0;
610  double mean_x_line1 = 0.0;
611  double mean_y_line1 = 0.0;
612  double sum_x_squared_line1 = 0.0;
613  double sum_squared_x_line1 = 0.0;
614  double b_line1;
615  double a_line1;
616  double num_elements_line1 = 3.0;
617 
618  for(ossim_int32 i = 0; i < num_elements_line1; ++i)
619  {
620  sum_xy_line1 = sum_xy_line1
621  + (line1RegPtsSamples[i]*line1RegPtsLines[i]);
622 
623  sum_x_line1 = sum_x_line1 + line1RegPtsSamples[i];
624  sum_y_line1 = sum_y_line1 + line1RegPtsLines[i];
625 
626  sum_squared_x_line1 = sum_squared_x_line1
627  + line1RegPtsSamples[i]*line1RegPtsSamples[i];
628  }
629 
630  sum_x_squared_line1 = sum_x_line1*sum_x_line1;
631  mean_y_line1 = sum_y_line1/num_elements_line1;
632  mean_x_line1 = sum_x_line1/num_elements_line1;
633  b_line1 = (sum_xy_line1 - (sum_x_line1*sum_y_line1)/num_elements_line1)
634  / (sum_squared_x_line1 - (sum_x_squared_line1/num_elements_line1));
635  a_line1 = mean_y_line1 - b_line1*mean_x_line1;
636 
637  if(traceDebug())
638  {
639  ossimNotify(ossimNotifyLevel_DEBUG)<<" a_line1: "<< a_line1 <<std::endl;
640  ossimNotify(ossimNotifyLevel_DEBUG)<<" b_line1: "<< b_line1 <<std::endl;
641 
642 
643  for(ossim_int32 i = 0; i < num_elements_line1; ++i)
644  {
645 
646  ossimNotify(ossimNotifyLevel_DEBUG) << setprecision(15) << "line1RegPtsLines[" << i
647  << "]: " <<line1RegPtsLines[i]
648  << "\nline1RegPtsSamples[" << i << "]: "
649  <<line1RegPtsSamples[i]
650  << std::endl;
651 
652  }
653  }
654 
655  //Regression Line 2
656  ossim_int32 line2_pt0 = rightMostSampleLine;
657  ossim_int32 line2_pt4 = bottomLine;
658  ossim_int32 line2_pt2 = (line2_pt0 + line2_pt4)/2;
659  ossim_int32 line2_pt1 = (line2_pt2 + line2_pt0)/2;
660  ossim_int32 line2_pt3 = (line2_pt2 + line2_pt4)/2;
661 
662 
663  ossim_int32 minValuePt1;
664  ossim_int32 minOffsetPt1;
665  getMinAndIndex(&theRightEdge[line2_pt1-100],
666  &theRightEdge[line2_pt1+100],
667  minValuePt1, minOffsetPt1 );
668  line2_pt1 = line2_pt1-100 + minOffsetPt1;
669 
670  ossim_int32 minValuePt2;
671  ossim_int32 minOffsetPt2;
672  getMinAndIndex(&theRightEdge[line2_pt2-100],
673  &theRightEdge[line2_pt2+100],
674  minValuePt2, minOffsetPt2 );
675  line2_pt2 = line2_pt2-100 + minOffsetPt2;
676 
677 
678  ossim_int32 minValuePt3;
679  ossim_int32 minOffsetPt3;
680  getMinAndIndex(&theRightEdge[line2_pt3-100],&theRightEdge[line2_pt3+100],
681  minValuePt3, minOffsetPt3 );
682  line2_pt3 = line2_pt3-100 + minOffsetPt3;
683 
684  //---
685  // Find the line within 100 lines of line2_ptx that has the
686  // minimum sample. This will cut off the 'fringe'
687  //---
688  double line2RegPtsSamples[] = { static_cast<double>(theRightEdge[line2_pt1]),
689  static_cast<double>(theRightEdge[line2_pt2]),
690  static_cast<double>(theRightEdge[line2_pt3]) };
691  double line2RegPtsLines[] = { static_cast<double>(-line2_pt1),
692  static_cast<double>(-line2_pt2),
693  static_cast<double>(-line2_pt3) };
694 
695  double sum_xy_line2 = 0.0;
696  double sum_x_line2 = 0.0;
697  double sum_y_line2 = 0.0;
698  double mean_x_line2 = 0.0;
699  double mean_y_line2 = 0.0;
700  double sum_x_squared_line2 = 0.0;
701  double sum_squared_x_line2 = 0.0;
702  double b_line2;
703  double a_line2;
704  double num_elements_line2 = 3.0;
705 
706  for(ossim_int32 i = 0; i < num_elements_line2; ++i)
707  {
708  sum_xy_line2 = sum_xy_line2
709  + (line2RegPtsSamples[i]*line2RegPtsLines[i]);
710 
711  sum_x_line2 = sum_x_line2 + line2RegPtsSamples[i];
712  sum_y_line2 = sum_y_line2 + line2RegPtsLines[i];
713 
714  sum_squared_x_line2 = sum_squared_x_line2
715  + line2RegPtsSamples[i]*line2RegPtsSamples[i];
716  }
717 
718  sum_x_squared_line2 = sum_x_line2*sum_x_line2;
719  mean_y_line2 = sum_y_line2/num_elements_line2;
720  mean_x_line2 = sum_x_line2/num_elements_line2;
721  b_line2 = (sum_xy_line2 - (sum_x_line2*sum_y_line2)/num_elements_line2)
722  / (sum_squared_x_line2 - (sum_x_squared_line2/num_elements_line2));
723  a_line2 = mean_y_line2 - b_line2*mean_x_line2;
724 
725  if(traceDebug())
726  {
727  for(ossim_int32 i = 0; i < num_elements_line2; ++i)
728  {
729  ossimNotify(ossimNotifyLevel_DEBUG) << setprecision(15) << "line2RegPtsLines[" << i << "]: "
730  <<line2RegPtsLines[i]
731  << "\nline2RegPtsSamples[" << i << "]: "
732  <<line2RegPtsSamples[i]
733  <<std::endl;
734  }
735  ossimNotify(ossimNotifyLevel_DEBUG) << "\na_line2: " << a_line2
736  << "\nb_line2: " << b_line2 << std::endl;
737 
738  }
739 
740  //End regression line2
741 
742  //Intersect lines 1 and 2 to get the ur corner vertex
743 
744  double ur_x = (a_line1 - a_line2)/(b_line2 - b_line1);
745  double ur_y = -(a_line1 + b_line1*ur_x);
746 
747  //Regression Line 3
748 
749  ossim_int32 line3_pt0 = leftMostSampleLine;
750  ossim_int32 line3_pt4 = bottomLine;
751  ossim_int32 line3_pt2 = (line3_pt0 + line3_pt4)/2;
752  ossim_int32 line3_pt1 = (line3_pt2 + line3_pt0)/2;
753  ossim_int32 line3_pt3 = (line3_pt2 + line3_pt4)/2;
754 
755  double line3RegPtsSamples[] = { static_cast<double>(theLeftEdge[line3_pt1]),
756  static_cast<double>(theLeftEdge[line3_pt2]),
757  static_cast<double>(theLeftEdge[line3_pt3]) };
758  double line3RegPtsLines[] = { static_cast<double>(-line3_pt1),
759  static_cast<double>(-line3_pt2),
760  static_cast<double>(-line3_pt3) };
761 
762  double sum_xy_line3 = 0.0;
763  double sum_x_line3 = 0.0;
764  double sum_y_line3 = 0.0;
765  double mean_x_line3 = 0.0;
766  double mean_y_line3 = 0.0;
767  double sum_x_squared_line3 = 0.0;
768  double sum_squared_x_line3 = 0.0;
769  double b_line3;
770  double a_line3;
771  double num_elements_line3 = 3.0;
772 
773  for(ossim_int32 i = 0; i < num_elements_line3; ++i)
774  {
775  sum_xy_line3 = sum_xy_line3
776  + (line3RegPtsSamples[i]*line3RegPtsLines[i]);
777 
778  sum_x_line3 = sum_x_line3 + line3RegPtsSamples[i];
779  sum_y_line3 = sum_y_line3 + line3RegPtsLines[i];
780 
781  sum_squared_x_line3 = sum_squared_x_line3
782  + line3RegPtsSamples[i]*line3RegPtsSamples[i];
783 
784  }
785 
786  sum_x_squared_line3 = sum_x_line3*sum_x_line3;
787  mean_y_line3 = sum_y_line3/num_elements_line3;
788  mean_x_line3 = sum_x_line3/num_elements_line3;
789  b_line3 = (sum_xy_line3 - (sum_x_line3*sum_y_line3)/num_elements_line3)
790  / (sum_squared_x_line3 - (sum_x_squared_line3/num_elements_line3));
791  a_line3 = mean_y_line3 - b_line3*mean_x_line3;
792 
793  if(traceDebug())
794  {
795  ossimNotify(ossimNotifyLevel_DEBUG) << "\n\n a_line3: " << a_line3 <<std::endl;
796  ossimNotify(ossimNotifyLevel_DEBUG) << " b_line3: " << b_line3 <<std::endl;
797 
798 
799  for(ossim_int32 i = 0; i < num_elements_line3; ++i)
800  {
801 
802  ossimNotify(ossimNotifyLevel_DEBUG) << setprecision(15) << "line3RegPtsLines[" << i << "]: "
803  <<line3RegPtsLines[i]
804  << "\nline3RegPtsSamples[" << i << "]: "
805  <<line3RegPtsSamples[i]
806  << std::endl;
807  }
808  }
809  //End regression line3
810 
811  //Intersect lines 2 and 3 to get the lr corner vertex
812 
813  double lr_x = (a_line3 - a_line2)/(b_line2 - b_line3);
814  double lr_y = -(a_line3 + b_line3*lr_x);
815 
816  //End Regression Line3
817 
818  //Regression Line 4
819 
820  ossim_int32 line4_pt0 = leftMostSampleLine;
821  ossim_int32 line4_pt4 = topLine;
822  ossim_int32 line4_pt2 = (line4_pt0 + line4_pt4)/2;
823  ossim_int32 line4_pt1 = (line4_pt2 + line4_pt0)/2;
824  ossim_int32 line4_pt3 = (line4_pt2 + line4_pt4)/2;
825 
826 // //***
827 // // Find the line within 100 lines of line2_ptx that has the maximum
828 // // sample. This will cut off the 'fringe'.
829 // //***
830 
831  ossim_int32 maxValueLine4Pt1;
832  ossim_int32 maxOffsetLine4Pt1;
833  getMaxAndIndex(&theLeftEdge[line4_pt1-100],&theLeftEdge[line4_pt1+100],
834  maxValueLine4Pt1, maxOffsetLine4Pt1 );
835  line4_pt1 = line4_pt1-100 + maxOffsetLine4Pt1;
836 
837 
838  ossim_int32 maxValueLine4Pt2;
839  ossim_int32 maxOffsetLine4Pt2;
840  getMaxAndIndex(&theLeftEdge[line4_pt2-100],&theLeftEdge[line4_pt2+100],
841  maxValueLine4Pt2, maxOffsetLine4Pt2 );
842  line4_pt2 = line4_pt2-100 + maxOffsetLine4Pt2;
843 
844 
845  ossim_int32 maxValueLine4Pt3;
846  ossim_int32 maxOffsetLine4Pt3;
847  getMaxAndIndex(&theLeftEdge[line4_pt3-100],&theLeftEdge[line4_pt3+100],
848  maxValueLine4Pt3, maxOffsetLine4Pt3 );
849  line4_pt3 = line4_pt3-100 + maxOffsetLine4Pt3;
850 
851 
852 
853 
854  double line4RegPtsSamples[] = { static_cast<double>(theLeftEdge[line4_pt1]),
855  static_cast<double>(theLeftEdge[line4_pt2]),
856  static_cast<double>(theLeftEdge[line4_pt3]) };
857  double line4RegPtsLines[] = { static_cast<double>(-line4_pt1),
858  static_cast<double>(-line4_pt2),
859  static_cast<double>(-line4_pt3) };
860 
861  double sum_xy_line4 = 0.0;
862  double sum_x_line4 = 0.0;
863  double sum_y_line4 = 0.0;
864  double mean_x_line4 = 0.0;
865  double mean_y_line4 = 0.0;
866  double sum_x_squared_line4 = 0.0;
867  double sum_squared_x_line4 = 0.0;
868  double b_line4;
869  double a_line4;
870  double num_elements_line4 = 3.0;
871  for(ossim_int32 i = 0; i < num_elements_line4; ++i)
872  {
873  sum_xy_line4 = sum_xy_line4
874  + (line4RegPtsSamples[i]*line4RegPtsLines[i]);
875 
876  sum_x_line4 = sum_x_line4 + line4RegPtsSamples[i];
877  sum_y_line4 = sum_y_line4 + line4RegPtsLines[i];
878 
879  sum_squared_x_line4 = sum_squared_x_line4
880  + line4RegPtsSamples[i]*line4RegPtsSamples[i];
881 
882 
883  }
884 
885  sum_x_squared_line4 = sum_x_line4*sum_x_line4;
886  mean_y_line4 = sum_y_line4/num_elements_line4;
887  mean_x_line4 = sum_x_line4/num_elements_line4;
888  b_line4 = (sum_xy_line4 - (sum_x_line4*sum_y_line4)/num_elements_line4)
889  / (sum_squared_x_line4 - (sum_x_squared_line4/num_elements_line4));
890  a_line4 = mean_y_line4 - b_line4*mean_x_line4;
891 
892  if(traceDebug())
893  {
894  ossimNotify(ossimNotifyLevel_DEBUG)<<"\na_line4: "<< a_line4
895  <<"\nb_line4: "<< b_line4 <<std::endl;
896 
897  for(ossim_int32 i = 0; i < num_elements_line4; ++i)
898  {
899 
900  ossimNotify(ossimNotifyLevel_DEBUG) << setprecision(15) << "line4RegPtsLines[" << i << "]: "
901  <<line4RegPtsLines[i]
902  << "\nline4RegPtsSamples[" << i << "]: "
903  <<line4RegPtsSamples[i]
904  << std::endl;
905 
906  }
907  }
908  //End regression line4
909 
910  //Intersect lines 3 and 4 to get the ll corner vertex
911 
912  double ll_x = (a_line4 - a_line3)/(b_line3 - b_line4);
913  double ll_y = -(a_line4 + b_line4*ll_x);
914 
915  //End Regression Line4
916 
917  //Intersect lines 4 and 1 to get the ul corner vertex
918 
919  double ul_x = (a_line4 - a_line1)/(b_line1 - b_line4);
920  double ul_y = -(a_line4 + b_line4*ul_x);
921 
922  if (traceDebug())
923  {
924  ossimNotify(ossimNotifyLevel_DEBUG)<<"\n\nInitial corners for tilted right: "
925  <<"\ncorner0: ("<<ul_x<<", "<<ul_y<<")"
926  <<"\ncorner1: ("<<ur_x<<", "<<ur_y<<")"
927  <<"\ncorner2: ("<<lr_x<<", "<<lr_y<<")"
928  <<"\ncorner3: ("<<ll_x<<", "<<ll_y<<")"<<std::endl<<std::endl;
929  }
930 
931  leftCornerLine_A = (ossim_int32)ul_y;
932  leftCorner_A = (ossim_int32)ul_x; //0
933 
934  rightCornerLine_A = (ossim_int32)ur_y;
935  rightCorner_A = (ossim_int32)ur_x; //1
936 
937  rightCornerLine_B = (ossim_int32)lr_y;
938  rightCorner_B =(ossim_int32)lr_x; //2
939 
940  leftCornerLine_B = (ossim_int32)ll_y;
941  leftCorner_B =(ossim_int32)ll_x; //3
942 
943 
944  // Check for bad corner points due to irregular shape image
945 
946  //for corner 0 (ul), sample should be between left and right most samples
947  // line can go negative due to jagged edges
948 
949  //for corner 1 (ur), sample can go > than num samples
950  // line should be between top and bottom lines
951 
952  //for corner 2 (lr), line should be between top and bottom line + 200
953  // sample should be between left and right most sample
954 
955  //for corner 3 (ll), line should be between top and bottom line
956  // sample should can go negative due to jagged edges
957 
958  if( (leftCornerLine_A < (topLine - 300))
959  || (leftCornerLine_A > total_lines)
960  || (leftCorner_A > rightMostSample)
961  || (leftCorner_A < leftMostSample)
962 
963  || (rightCornerLine_A < topLine)
964  || (rightCornerLine_A > bottomLine)
965  || (rightCorner_A < leftMostSample)
966  || (rightCorner_A > (rightMostSample + 200))
967 
968 
969  || (rightCornerLine_B < topLine)
970  || (rightCornerLine_B > (bottomLine + 200))
971  || (rightCorner_B < leftMostSample)
972  || (rightCorner_B > rightMostSample)
973 
974  || (leftCornerLine_B > bottomLine)
975  || (leftCornerLine_B < topLine)
976  || (leftCorner_B > rightMostSample)
977  || (leftCorner_B < (leftMostSample - 200)) )
978 
979 
980 
981  {
982  right = false;
983  if (traceDebug())
984  {
985  ossimNotify(ossimNotifyLevel_DEBUG) <<"\n\n***Case = NOT TILTED RIGHT...***"<<std::endl;
986  }
987  }
988  }
989 
990  //tilted left
991  if(firstRightSample > lastRightSample)
992  {//begin tilted left
993 
994  if (traceDebug())
995  {
996  ossimNotify(ossimNotifyLevel_DEBUG) <<"\n\n***Case = TILTED LEFT***"<<std::endl;
997  }
998  left = true;
999 
1000  // Regression line 1 is the right side
1001  // Regression line 3 is the left side
1002  // These are handled differently
1003  // These sides may be 'uneven' or 'torn' or 'louvered'
1004  // This code finds the best regression line that 'cuts off' this edge fringe
1005 
1006 
1007  //Regression Line 1
1008 
1009  ossim_int32 line1_pt4 = rightMostSampleLine;
1010  ossim_int32 line1_pt0 = topLine;
1011  ossim_int32 line1_pt2 = (line1_pt0 + line1_pt4)/2;
1012  ossim_int32 line1_pt1 = (line1_pt2 + line1_pt0)/2;
1013  ossim_int32 line1_pt3 = (line1_pt2 + line1_pt4)/2;
1014 
1015  if (traceDebug())
1016  {
1017  ossimNotify(ossimNotifyLevel_DEBUG)<<" line1_pt1: "<<line1_pt0<<std::endl;
1018  ossimNotify(ossimNotifyLevel_DEBUG)<<" line1_pt2: "<<line1_pt1<<std::endl;
1019  ossimNotify(ossimNotifyLevel_DEBUG)<<" line1_pt3: "<<line1_pt2<<std::endl;
1020  ossimNotify(ossimNotifyLevel_DEBUG)<<" line1_pt4: "<<line1_pt3<<std::endl;
1021  }
1022 
1023  ossim_int32 minValueLine1Pt1;
1024  ossim_int32 minOffsetLine1Pt1;
1025  getMinAndIndex(&theLeftEdge[line1_pt1-100],&theLeftEdge[line1_pt1+100],
1026  minValueLine1Pt1, minOffsetLine1Pt1 );
1027  line1_pt1 = line1_pt1-100 + minOffsetLine1Pt1;
1028 
1029  if (traceDebug())
1030  {
1031  ossimNotify(ossimNotifyLevel_DEBUG) << " line1_pt1: "<< line1_pt1
1032  <<" minValueLine1Pt1: "<<minValueLine1Pt1<<"\n\n";
1033  }
1034 
1035  ossim_int32 minValueLine1Pt2;
1036  ossim_int32 minOffsetLine1Pt2;
1037  getMinAndIndex(&theLeftEdge[line1_pt2-100],&theLeftEdge[line1_pt2+100],
1038  minValueLine1Pt2, minOffsetLine1Pt2 );
1039  line1_pt2 = line1_pt2-100 + minOffsetLine1Pt2;
1040 
1041  if (traceDebug())
1042  {
1043  ossimNotify(ossimNotifyLevel_DEBUG) << " line1_pt2: "<< line1_pt2
1044  <<" minValueLine1Pt2: "<<minValueLine1Pt2<<"\n\n";
1045  }
1046 
1047 
1048  ossim_int32 minValueLine1Pt3;
1049  ossim_int32 minOffsetLine1Pt3;
1050  getMinAndIndex(&theLeftEdge[line1_pt3-100],&theLeftEdge[line1_pt3+100],
1051  minValueLine1Pt3, minOffsetLine1Pt3 );
1052  line1_pt3 = line1_pt3-100 + minOffsetLine1Pt3;
1053 
1054  if (traceDebug())
1055  {
1056  ossimNotify(ossimNotifyLevel_DEBUG) << " line1_pt3: "<< line1_pt3
1057  <<" minValueLine1Pt3: "<<minValueLine1Pt3<<std::endl<<std::endl;
1058  }
1059 
1060  double line1RegPtsSamples[] = { static_cast<double>(theRightEdge[line1_pt1]),
1061  static_cast<double>(theRightEdge[line1_pt2]),
1062  static_cast<double>(theRightEdge[line1_pt3])};
1063  double line1RegPtsLines[] = { static_cast<double>(-line1_pt1),
1064  static_cast<double>(-line1_pt2),
1065  static_cast<double>(-line1_pt3) };
1066 
1067  double sum_xy_line1 = 0.0;
1068  double sum_x_line1 = 0.0;
1069  double sum_y_line1 = 0.0;
1070  double mean_x_line1 = 0.0;
1071  double mean_y_line1 = 0.0;
1072  double sum_x_squared_line1 = 0.0;
1073  double sum_squared_x_line1 = 0.0;
1074  double b_line1;
1075  double a_line1;
1076  double num_elements_line1 = 3.0;
1077 
1078  for(ossim_int32 i = 0; i < num_elements_line1; ++i)
1079  {
1080  sum_xy_line1 = sum_xy_line1
1081  + (line1RegPtsSamples[i]*line1RegPtsLines[i]);
1082 
1083  sum_x_line1 = sum_x_line1 + line1RegPtsSamples[i];
1084  sum_y_line1 = sum_y_line1 + line1RegPtsLines[i];
1085 
1086  sum_squared_x_line1 = sum_squared_x_line1
1087  + line1RegPtsSamples[i]*line1RegPtsSamples[i];
1088 
1089 
1090  }
1091 
1092  sum_x_squared_line1 = sum_x_line1*sum_x_line1;
1093  mean_y_line1 = sum_y_line1/num_elements_line1;
1094  mean_x_line1 = sum_x_line1/num_elements_line1;
1095  b_line1 = (sum_xy_line1 - (sum_x_line1*sum_y_line1)/num_elements_line1)
1096  / (sum_squared_x_line1 - (sum_x_squared_line1/num_elements_line1));
1097  a_line1 = mean_y_line1 - b_line1*mean_x_line1;
1098 
1099  if(traceDebug())
1100  {
1101  ossimNotify(ossimNotifyLevel_DEBUG)<<"a_line1: "<< a_line1
1102  <<"\nb_line1: "<< b_line1 <<std::endl;
1103 
1104  for(ossim_int32 i = 0; i < num_elements_line1; ++i)
1105  {
1106 
1107  ossimNotify(ossimNotifyLevel_DEBUG) << setprecision(15) << "line1RegPtsLines[" << i << "]: "
1108  <<line1RegPtsLines[i]
1109  << "\nline1RegPtsSamples[" << i << "]: "
1110  <<line1RegPtsSamples[i]
1111  << std::endl;
1112  }
1113  }
1114 
1115 
1116  //Regression Line 2
1117 
1118  ossim_int32 line2_pt0 = rightMostSampleLine;
1119  ossim_int32 line2_pt4 = bottomLine;
1120  ossim_int32 line2_pt2 = (line2_pt0 + line2_pt4)/2;
1121  ossim_int32 line2_pt1 = (line2_pt2 + line2_pt0)/2;
1122  ossim_int32 line2_pt3 = (line2_pt2 + line2_pt4)/2;
1123 
1124  double line2RegPtsSamples[] = { static_cast<double>(theRightEdge[line2_pt1]),
1125  static_cast<double>(theRightEdge[line2_pt2]),
1126  static_cast<double>(theRightEdge[line2_pt3]) };
1127  double line2RegPtsLines[] = { static_cast<double>(-line2_pt1),
1128  static_cast<double>(-line2_pt2),
1129  static_cast<double>(-line2_pt3) };
1130 
1131  double sum_xy_line2 = 0.0;
1132  double sum_x_line2 = 0.0;
1133  double sum_y_line2 = 0.0;
1134  double mean_x_line2 = 0.0;
1135  double mean_y_line2 = 0.0;
1136  double sum_x_squared_line2 = 0.0;
1137  double sum_squared_x_line2 = 0.0;
1138  double b_line2;
1139  double a_line2;
1140  double num_elements_line2 = 3.0;
1141  for(ossim_int32 i = 0; i < num_elements_line2; ++i)
1142  {
1143  sum_xy_line2 = sum_xy_line2
1144  + (line2RegPtsSamples[i]*line2RegPtsLines[i]);
1145 
1146  sum_x_line2 = sum_x_line2 + line2RegPtsSamples[i];
1147  sum_y_line2 = sum_y_line2 + line2RegPtsLines[i];
1148 
1149  sum_squared_x_line2 = sum_squared_x_line2
1150  + line2RegPtsSamples[i]*line2RegPtsSamples[i];
1151  }
1152 
1153  sum_x_squared_line2 = sum_x_line2*sum_x_line2;
1154  mean_y_line2 = sum_y_line2/num_elements_line2;
1155  mean_x_line2 = sum_x_line2/num_elements_line2;
1156  b_line2 = (sum_xy_line2 - (sum_x_line2*sum_y_line2)/num_elements_line2)
1157  / (sum_squared_x_line2 - (sum_x_squared_line2/num_elements_line2));
1158  a_line2 = mean_y_line2 - b_line2*mean_x_line2;
1159 
1160  if(traceDebug())
1161  {
1162  ossimNotify(ossimNotifyLevel_DEBUG) << "a_line2: "<< a_line2
1163  << "\nb_line2: "<< b_line2 <<std::endl;
1164 
1165  for(ossim_int32 i = 0; i < num_elements_line2; ++i)
1166  {
1167 
1168  ossimNotify(ossimNotifyLevel_DEBUG) << setprecision(15) << "line2RegPtsLines[" << i << "]: "
1169  <<line2RegPtsLines[i]
1170  << "\nline2RegPtsSamples[" << i << "]: "
1171  <<line2RegPtsSamples[i]
1172  << std::endl;
1173  }
1174  }
1175  //End regression line2
1176 
1177  //Intersect lines 1 and 2 to get the lr corner vertex
1178 
1179  double lr_x = (a_line1 - a_line2)/(b_line2 - b_line1);
1180  double lr_y = -(a_line1 + b_line1*lr_x);
1181 
1182  //Regression Line 3
1183 
1184  ossim_int32 line3_pt0 = leftMostSampleLine;
1185  ossim_int32 line3_pt4 = bottomLine;
1186  ossim_int32 line3_pt2 = (line3_pt0 + line3_pt4)/2;
1187  ossim_int32 line3_pt1 = (line3_pt2 + line3_pt0)/2;
1188  ossim_int32 line3_pt3 = (line3_pt2 + line3_pt4)/2;
1189 
1190  ossim_int32 maxValueLine3Pt1;
1191  ossim_int32 maxOffsetLine3Pt1;
1192  getMaxAndIndex(&theLeftEdge[line3_pt1-100],&theLeftEdge[line3_pt1+100],
1193  maxValueLine3Pt1, maxOffsetLine3Pt1 );
1194  line3_pt1 = line3_pt1-100 + maxOffsetLine3Pt1;
1195 
1196 
1197  ossim_int32 maxValueLine3Pt2;
1198  ossim_int32 maxOffsetLine3Pt2;
1199  getMaxAndIndex(&theLeftEdge[line3_pt2-100],&theLeftEdge[line3_pt2+100],
1200  maxValueLine3Pt2, maxOffsetLine3Pt2 );
1201  line3_pt2 = line3_pt2-100 + maxOffsetLine3Pt2;
1202 
1203 
1204  ossim_int32 maxValueLine3Pt3;
1205  ossim_int32 maxOffsetLine3Pt3;
1206  getMaxAndIndex(&theLeftEdge[line3_pt3-100],&theLeftEdge[line3_pt3+100],
1207  maxValueLine3Pt3, maxOffsetLine3Pt3 );
1208  line3_pt3 = line3_pt3-100 + maxOffsetLine3Pt3;
1209 
1210 
1211  double line3RegPtsSamples[] = { static_cast<double>(theLeftEdge[line3_pt1]),
1212  static_cast<double>(theLeftEdge[line3_pt2]),
1213  static_cast<double>(theLeftEdge[line3_pt3]) };
1214  double line3RegPtsLines[] = { static_cast<double>(-line3_pt1),
1215  static_cast<double>(-line3_pt2),
1216  static_cast<double>(-line3_pt3) };
1217 
1218  double sum_xy_line3 = 0.0;
1219  double sum_x_line3 = 0.0;
1220  double sum_y_line3 = 0.0;
1221  double mean_x_line3 = 0.0;
1222  double mean_y_line3 = 0.0;
1223  double sum_x_squared_line3 = 0.0;
1224  double sum_squared_x_line3 = 0.0;
1225  double b_line3;
1226  double a_line3;
1227  double num_elements_line3 = 3.0;
1228  for(ossim_int32 i = 0; i < num_elements_line3; ++i)
1229  {
1230  sum_xy_line3 = sum_xy_line3
1231  + (line3RegPtsSamples[i]*line3RegPtsLines[i]);
1232 
1233  sum_x_line3 = sum_x_line3 + line3RegPtsSamples[i];
1234  sum_y_line3 = sum_y_line3 + line3RegPtsLines[i];
1235 
1236  sum_squared_x_line3 = sum_squared_x_line3
1237  + line3RegPtsSamples[i]*line3RegPtsSamples[i];
1238 
1239 
1240  }
1241 
1242  sum_x_squared_line3 = sum_x_line3*sum_x_line3;
1243  mean_y_line3 = sum_y_line3/num_elements_line3;
1244  mean_x_line3 = sum_x_line3/num_elements_line3;
1245  b_line3 = (sum_xy_line3 - (sum_x_line3*sum_y_line3)/num_elements_line3)
1246  / (sum_squared_x_line3 - (sum_x_squared_line3/num_elements_line3));
1247  a_line3 = mean_y_line3 - b_line3*mean_x_line3;
1248 
1249  if(traceDebug())
1250  {
1251  ossimNotify(ossimNotifyLevel_DEBUG)<<"\n\n a_line3: "<< a_line3 <<std::endl
1252  <<" b_line3: "<< b_line3 <<endl;
1253  for(ossim_int32 i = 0; i < num_elements_line3; ++i)
1254  {
1255 
1256  ossimNotify(ossimNotifyLevel_DEBUG) << setprecision(15) << "line3RegPtsLines[" << i << "]: "
1257  << line3RegPtsLines[i]
1258  << "\nline3RegPtsSamples[" << i << "]: "
1259  << line3RegPtsSamples[i]
1260  << std::endl;
1261  }
1262  }
1263  //End regression line3
1264 
1265  //Intersect lines 2 and 3 to get the ll corner vertex
1266 
1267  double ll_x = (a_line3 - a_line2)/(b_line2 - b_line3);
1268  double ll_y = -(a_line3 + b_line3*ll_x);
1269 
1270  //End Regression Line3
1271 
1272  //Regression Line 4
1273 
1274  ossim_int32 line4_pt0 = leftMostSampleLine;
1275  ossim_int32 line4_pt4 = topLine;
1276  ossim_int32 line4_pt2 = (line4_pt0 + line4_pt4)/2;
1277  ossim_int32 line4_pt1 = (line4_pt2 + line4_pt0)/2;
1278  ossim_int32 line4_pt3 = (line4_pt2 + line4_pt4)/2;
1279 
1280 
1281  double line4RegPtsSamples[] = { static_cast<double>(theLeftEdge[line4_pt1]),
1282  static_cast<double>(theLeftEdge[line4_pt2]),
1283  static_cast<double>(theLeftEdge[line4_pt3])};
1284  double line4RegPtsLines[] = { static_cast<double>(-line4_pt1),
1285  static_cast<double>(-line4_pt2),
1286  static_cast<double>(-line4_pt3) };
1287 
1288  double sum_xy_line4 = 0.0;
1289  double sum_x_line4 = 0.0;
1290  double sum_y_line4 = 0.0;
1291  double mean_x_line4 = 0.0;
1292  double mean_y_line4 = 0.0;
1293  double sum_x_squared_line4 = 0.0;
1294  double sum_squared_x_line4 = 0.0;
1295  double b_line4;
1296  double a_line4;
1297  double num_elements_line4 = 3.0;
1298  for(ossim_int32 i = 0; i < num_elements_line4; ++i)
1299  {
1300  sum_xy_line4 = sum_xy_line4
1301  + (line4RegPtsSamples[i]*line4RegPtsLines[i]);
1302 
1303  sum_x_line4 = sum_x_line4 + line4RegPtsSamples[i];
1304  sum_y_line4 = sum_y_line4 + line4RegPtsLines[i];
1305 
1306  sum_squared_x_line4 = sum_squared_x_line4
1307  + line4RegPtsSamples[i]*line4RegPtsSamples[i];
1308 
1309 
1310  }
1311 
1312  sum_x_squared_line4 = sum_x_line4*sum_x_line4;
1313  mean_y_line4 = sum_y_line4/num_elements_line4;
1314  mean_x_line4 = sum_x_line4/num_elements_line4;
1315  b_line4 = (sum_xy_line4 - (sum_x_line4*sum_y_line4)/num_elements_line4)
1316  / (sum_squared_x_line4 - (sum_x_squared_line4/num_elements_line4));
1317  a_line4 = mean_y_line4 - b_line4*mean_x_line4;
1318 
1319  if(traceDebug())
1320  {
1321  ossimNotify(ossimNotifyLevel_DEBUG)<< "\n\n a_line4: "<< a_line4 <<std::endl;
1322  ossimNotify(ossimNotifyLevel_DEBUG)<< " b_line4: "<< b_line4 <<std::endl;
1323 
1324  for(ossim_int32 i = 0; i < num_elements_line4; ++i)
1325  {
1326  ossimNotify(ossimNotifyLevel_DEBUG) << setprecision(15) << "line4RegPtsLines[" << i << "]: "
1327  <<line4RegPtsLines[i]
1328  << "\nline4RegPtsSamples[" << i << "]: "
1329  <<line4RegPtsSamples[i]
1330  << std::endl;
1331  }
1332 
1333  }
1334  //End regression line 4
1335 
1336  //Intersect lines 3 and 4 to get the ul corner vertex
1337 
1338  double ul_x = (a_line4 - a_line3)/(b_line3 - b_line4);
1339  double ul_y = -(a_line4 + b_line4*ul_x);
1340  //End Regression Line4
1341 
1342  //Intersect lines 4 and 1 to get the ur corner vertex
1343 
1344  double ur_x = (a_line4 - a_line1)/(b_line1 - b_line4);
1345  double ur_y = -(a_line4 + b_line4*ur_x);
1346 
1347  if (traceDebug())
1348  {
1349  ossimNotify(ossimNotifyLevel_DEBUG) <<"Initial corners for tilted left: "
1350  <<"\ncorner0: ("<<ul_x<<", "<<ul_y<<")"
1351  <<"\ncorner1: ("<<ur_x<<", "<<ur_y<<")"
1352  <<"\ncorner2: ("<<lr_x<<", "<<lr_y<<")"
1353  <<"\ncorner3: ("<<ll_x<<", "<<ll_y<<")" <<std::endl;
1354  }
1355 
1356  leftCornerLine_A = (ossim_int32)ul_y;
1357  leftCorner_A = (ossim_int32)ul_x; //0
1358 
1359  rightCornerLine_A = (ossim_int32)ur_y;
1360  rightCorner_A = (ossim_int32)ur_x; //1
1361 
1362  rightCornerLine_B = (ossim_int32)lr_y;
1363  rightCorner_B =(ossim_int32)lr_x; //2
1364 
1365  leftCornerLine_B = (ossim_int32)ll_y;
1366  leftCorner_B =(ossim_int32)ll_x; //3
1367 
1368  // Check for bad corner points due to irregular shape image
1369 
1370  //for corner 0 (ul), line should be between top and bottom line
1371  // sample should can go negative due to jagged edges
1372 
1373  //for corner 1 (ur), sample should be between left and right most samples
1374  // line can go negative due to jagged edges
1375 
1376  //for corner 2 (lr), line should be between top and bottom lines
1377  // sample can be greater than rightMost samp due to jagged edges
1378 
1379  //for corner 3 (ll), line should be between top and bottom line + 200
1380  // sample should be between left and right most sample
1381  if( (leftCornerLine_A > bottomLine)
1382  || (leftCornerLine_A < topLine)
1383  || (leftCorner_A > rightMostSample)
1384  || (leftCorner_A < (leftMostSample - 300))
1385 
1386  || (rightCornerLine_A < (topLine - 300))
1387  || (rightCornerLine_A > total_lines)
1388  || (rightCorner_A > rightMostSample)
1389  || (rightCorner_A < leftMostSample)
1390 
1391 
1392  || (rightCornerLine_B < topLine)
1393  || (rightCornerLine_B > bottomLine)
1394  || (rightCorner_B < leftMostSample)
1395  || (rightCorner_B > (rightMostSample + 200))
1396 
1397  || (leftCornerLine_B > (bottomLine + 200))
1398  || (leftCornerLine_B < topLine)
1399  || (leftCorner_B < leftMostSample)
1400  || (leftCorner_B > rightMostSample) )
1401 
1402  {
1403  left = false;
1404 
1405  if (traceDebug())
1406  {
1407  ossimNotify(ossimNotifyLevel_DEBUG) <<"\n\n***Case = NOT TILTED LEFT..***"<<std::endl;
1408  }
1409  }
1410  }
1411  }
1412 
1413  if( (square == 0) && (rhombus == 0) && (right == 0) && (left == 0))
1414  {
1415  if (traceDebug())
1416  {
1417  ossimNotify(ossimNotifyLevel_DEBUG)<<"\nDefault case"<<std::endl;
1418  }
1419 
1420  //Suboptimal UL Corner:
1421  leftCornerLine_A = (topLine);
1422  leftCorner_A =(leftMostSample); //0
1423 
1424  //Look for non-null starting at topLine and going down
1425  //Starting at left most samp and moving right
1426 
1427  bool foundULcornera = false;
1428  bool foundULcornerb = false;
1429  ossimImageHandler* src = reinterpret_cast<ossimImageHandler*>(getInput(0));
1430 
1431  ossimIrect tileRectUL(leftMostSample,
1432  topLine,
1433  leftMostSample+50,
1434  (topLine + 50) );
1435 
1436  ossimRefPtr<ossimImageData> dataUL = src->getTile(tileRectUL);
1437  // ossimIrect imageRectangleUL = dataUL->getImageRectangle();
1438 
1439  ossim_int32 tempSamp_corner0a = 0;
1440  ossim_int32 tempLine_corner0a = 0;
1441  if (dataUL.valid())
1442  {
1443  for (ossim_int32 line = tileRectUL.ul().y; line <= tileRectUL.lr().y; ++line)
1444  {
1445  for (ossim_int32 samp = tileRectUL.ul().x; samp <=tileRectUL.ur().x; ++samp)
1446  {
1447  // uses band 0 corner points
1448  if(!(dataUL->isNull(ossimIpt(samp,line),0)))
1449  {
1450 
1451  foundULcornera = true;
1452 
1453  //Optimal Corner:
1454  leftCornerLine_A = line;//0
1455  leftCorner_A = samp;
1456  tempLine_corner0a = line;
1457  tempSamp_corner0a = samp;
1458 
1459  if (traceDebug())
1460  {
1462  <<"\nFound non null in ul corner pass 1 "<<std::endl
1463  <<"line: "<<line<<std::endl
1464  <<"samp: "<<samp<<std::endl;
1465  }
1466  }
1467  if(foundULcornera == true){break;}
1468  }
1469  if(foundULcornera == true){break;}
1470  }
1471 
1472  // Search in the other direction to handle the case of 'jaggered' edges.
1473  ossim_int32 tempSamp_corner0b = 0;
1474  ossim_int32 tempLine_corner0b = 0;
1475  for (ossim_int32 samp = tileRectUL.ul().x; samp <=tileRectUL.ur().x; ++samp)
1476  {
1477  for (ossim_int32 line = tileRectUL.ul().y; line <= tileRectUL.lr().y; ++line)
1478  {
1479  // uses band 0 corner points
1480  if(!(dataUL->isNull(ossimIpt(samp,line),0)))
1481  {
1482 
1483  foundULcornerb = true;
1484 
1485  //Optimal Corner:
1486  leftCornerLine_A = line;//0
1487  leftCorner_A = samp;
1488  tempLine_corner0b = line;
1489  tempSamp_corner0b = samp;
1490 
1491  if (traceDebug())
1492  {
1494  <<"\nFound non null in ul corner pass 2 "<<std::endl
1495  <<"line: "<<line<<std::endl
1496  <<"samp: "<<samp<<std::endl;
1497  }
1498  }
1499  if(foundULcornerb == true){break;}
1500  }
1501  if(foundULcornerb == true){break;}
1502  }
1503 
1504  //Better corner
1505  if(foundULcornerb == true && foundULcornera ==true)
1506  {
1507  leftCornerLine_B = (tempLine_corner0a + tempLine_corner0b)/2;
1508  leftCorner_B = (tempSamp_corner0a + tempSamp_corner0b)/2;
1509  }
1510 
1511 
1512  // Suboptimal UR corner:
1513  rightCornerLine_A = (topLine);
1514  rightCorner_A = (rightMostSample); //1
1515 
1516  }
1517  //Look for non-null starting at topLine and going down
1518  //Starting at right most samp and moving left
1519 
1520  bool foundURcornera = false;
1521  bool foundURcornerb = false;
1522 
1523  ossimIrect tileRectUR((rightMostSample - 50),
1524  topLine,
1525  rightMostSample,
1526  (topLine + 50) );
1527 
1528  ossimRefPtr<ossimImageData> dataUR = src->getTile(tileRectUR);
1529  // ossimIrect imageRectangleUR = dataUR->getImageRectangle();
1530 
1531  ossim_int32 tempSamp_corner1a = 0;
1532  ossim_int32 tempLine_corner1a = 0;
1533 
1534  if (dataUR.valid())
1535  {
1536  for (ossim_int32 line = tileRectUR.ul().y; line <= tileRectUR.lr().y; ++line)
1537  {
1538  for (ossim_int32 samp = tileRectUR.ur().x; samp > tileRectUR.ul().x; --samp)
1539  {
1540 
1541  if(!(dataUR->isNull(ossimIpt(samp,line),0)))
1542  {
1543 
1544  foundURcornera = true;
1545  rightCornerLine_A = line;
1546  rightCorner_A = samp;
1547  tempLine_corner1a = line;
1548  tempSamp_corner1a = samp;
1549 
1550  if (traceDebug())
1551  {
1553  <<"\nFound non null in ur corner pass 1 "<<std::endl
1554  <<"line: "<<line<<std::endl
1555  <<"samp: "<<samp<<std::endl;
1556  }
1557  }
1558  if(foundURcornera == true){break;}
1559  }
1560  if(foundURcornera == true){break;}
1561  }
1562 
1563  // Search in the other direction to handle the case of 'jaggered' edges.
1564  ossim_int32 tempSamp_corner1b = 0;
1565  ossim_int32 tempLine_corner1b = 0;
1566 
1567  for (ossim_int32 samp = tileRectUR.ur().x; samp > tileRectUR.ul().x; --samp)
1568  {
1569  for (ossim_int32 line = tileRectUR.ul().y; line <= tileRectUR.lr().y; ++line)
1570 
1571  {
1572  if(!(dataUR->isNull(ossimIpt(samp,line),0)))
1573  {
1574 
1575  foundURcornerb = true;
1576  rightCornerLine_A = line;
1577  rightCorner_A = samp;
1578  tempLine_corner1b = line;
1579  tempSamp_corner1b = samp;
1580 
1581  if (traceDebug())
1582  {
1584  <<"\nFound non null in ur corner pass 2 "<<std::endl
1585  <<"line: "<<line<<std::endl
1586  <<"samp: "<<samp<<std::endl;
1587  }
1588  }
1589  if(foundURcornerb == true){break;}
1590  }
1591  if(foundURcornerb == true){break;}
1592  }
1593 
1594  //Better corner
1595  if(foundURcornerb == true && foundURcornera ==true)
1596  {
1597  rightCornerLine_B = (tempLine_corner1a + tempLine_corner1b)/2;
1598  rightCorner_B = (tempSamp_corner1a + tempSamp_corner1b)/2;
1599  }
1600 
1601  // Suboptimal LR corner:
1602  rightCornerLine_B = (bottomLine);
1603  rightCorner_B = (rightMostSample); //2
1604 
1605  }
1606 
1607  //Look for non-null starting at bottomLine and going up
1608  //Starting at right most samp and moving left
1609 
1610  bool foundLRcornera = false;
1611  bool foundLRcornerb = false;
1612 
1613  ossimIrect tileRectLR((rightMostSample - 50),
1614  bottomLine - 50,
1615  rightMostSample,
1616  (bottomLine) );
1617 
1618  ossimRefPtr<ossimImageData> dataLR = src->getTile(tileRectLR);
1619  // ossimIrect imageRectangleLR = dataLR->getImageRectangle();
1620 
1621  ossim_int32 tempSamp_corner2a = 0;
1622  ossim_int32 tempLine_corner2a = 0;
1623 
1624  if (dataLR.valid())
1625  {
1626  for (ossim_int32 line = tileRectLR.lr().y; line >= tileRectLR.ur().y; --line)
1627  {
1628  for (ossim_int32 samp = tileRectLR.lr().x; samp > tileRectLR.ul().x; --samp)
1629  {
1630 
1631  if(!(dataLR->isNull(ossimIpt(samp,line),0)))
1632  {
1633 
1634  foundLRcornera = true;
1635  rightCornerLine_B = line;
1636  rightCorner_B = samp;
1637  tempLine_corner2a = line;
1638  tempSamp_corner2a = samp;
1639 
1640  if (traceDebug())
1641  {
1643  <<"\nFound non null in lr corner pass 1 "<<std::endl
1644  <<"line: "<<line<<std::endl
1645  <<"samp: "<<samp<<std::endl;
1646  }
1647  }
1648  if(foundLRcornera == true){break;}
1649  }
1650  if(foundLRcornera == true){break;}
1651  }
1652  // Search in the other direction to handle the case of 'jaggered' edges.
1653 
1654  ossim_int32 tempSamp_corner2b = 0;
1655  ossim_int32 tempLine_corner2b = 0;
1656 
1657  for (ossim_int32 samp = tileRectLR.lr().x; samp > tileRectLR.ul().x; --samp)
1658  {
1659  for (ossim_int32 line = tileRectLR.lr().y; line >= tileRectLR.ur().y; --line)
1660  {
1661  if(!(dataLR->isNull(ossimIpt(samp,line),0)))
1662  {
1663 
1664  foundLRcornerb = true;
1665  rightCornerLine_B = line;
1666  rightCorner_B = samp;
1667  tempLine_corner2b = line;
1668  tempSamp_corner2b = samp;
1669 
1670  if (traceDebug())
1671  {
1673  <<"\nFound non null in lr corner pass 2"<<std::endl
1674  <<"line: "<<line<<std::endl
1675  <<"samp: "<<samp<<std::endl;
1676  }
1677  }
1678  if(foundLRcornerb == true){break;}
1679  }
1680  if(foundLRcornerb == true){break;}
1681  }
1682  //Better corner
1683  if(foundLRcornerb == true && foundLRcornera ==true)
1684  {
1685  rightCornerLine_B = (tempLine_corner2a + tempLine_corner2b)/2;
1686  rightCorner_B = (tempSamp_corner2a + tempSamp_corner2b)/2;
1687  }
1688  // Suboptimal LL corner:
1689  leftCornerLine_B = (bottomLine);
1690  leftCorner_B = (leftMostSample); //3
1691 
1692  }
1693 
1694  //Look for non-null starting at bottomLine and going up
1695  //Starting at left most samp and moving right
1696 
1697  bool foundLLcornera = false;
1698  bool foundLLcornerb = false;
1699 
1700  ossimIrect tileRectLL((leftMostSample),
1701  (bottomLine - 50),
1702  (leftMostSample +50),
1703  (bottomLine) );
1704 
1705  ossimRefPtr<ossimImageData> dataLL = src->getTile(tileRectLL);
1706  // ossimIrect imageRectangleLL = dataLL->getImageRectangle();
1707 
1708  ossim_int32 tempSamp_corner3a = 0;
1709  ossim_int32 tempLine_corner3a = 0;
1710 
1711  if (dataLL.valid())
1712  {
1713  for (ossim_int32 samp = tileRectLL.ul().x; samp <= tileRectLL.ur().x; ++samp)
1714  {
1715 
1716  for (ossim_int32 line = tileRectLL.lr().y; line >= tileRectLL.ul().y; --line)
1717 
1718  {
1719 
1720  if(!(dataLL->isNull(ossimIpt(samp,line),0)))
1721  {
1722 
1723  foundLLcornera = true;
1724  leftCornerLine_B = line;
1725  leftCorner_B = samp;
1726  tempLine_corner3a = line;
1727  tempSamp_corner3a = samp;
1728 
1729  if (traceDebug())
1730  {
1732  <<"\nFound non null in ll corner pass 1"<<std::endl
1733  <<"line: "<<line<<std::endl
1734  <<"samp: "<<samp<<std::endl;
1735  }
1736  }
1737  if(foundLLcornera == true){break;}
1738  }
1739  if(foundLLcornera == true){break;}
1740  }
1741 
1742  // Search in the other direction to handle the case of 'jaggered' edges.
1743 
1744  ossim_int32 tempSamp_corner3b = 0;
1745  ossim_int32 tempLine_corner3b = 0;
1746  for (ossim_int32 line = tileRectLL.lr().y; line >= tileRectLL.ul().y; --line)
1747  {
1748 
1749  for (ossim_int32 samp = tileRectLL.ul().x; samp <= tileRectLL.ur().x; ++samp)
1750 
1751  {
1752 
1753  if(!(dataLL->isNull(ossimIpt(samp,line),0)))
1754  {
1755 
1756  foundLLcornerb = true;
1757  leftCornerLine_B = line;
1758  leftCorner_B = samp;
1759  tempLine_corner3b = line;
1760  tempSamp_corner3b = samp;
1761 
1762  if (traceDebug())
1763  {
1765  <<"\nFound non null in ll corner pass 2 "<<std::endl
1766  <<"line: "<<line<<std::endl
1767  <<"samp: "<<samp<<std::endl;
1768  }
1769  }
1770  if(foundLLcornerb == true){break;}
1771  }
1772  if(foundLLcornerb == true){break;}
1773  }
1774 
1775  //Better corner
1776  if(foundLLcornerb == true && foundLLcornera ==true)
1777  {
1778  leftCornerLine_B = (tempLine_corner3a + tempLine_corner3b)/2;
1779  leftCorner_B = (tempSamp_corner3a + tempSamp_corner3b)/2;
1780  }
1781  }
1782  }
1783 
1784  theVertice[0].x = leftCorner_A;
1785  theVertice[0].y = leftCornerLine_A;
1786 
1787  theVertice[1].x = rightCorner_A;
1788  theVertice[1].y = rightCornerLine_A;
1789 
1790  theVertice[3].x = leftCorner_B;
1791  theVertice[3].y = leftCornerLine_B;
1792 
1793  theVertice[2].x = rightCorner_B;
1794  theVertice[2].y = rightCornerLine_B;
1795 
1796  if (leftSlope)
1797  {
1798  delete [] leftSlope;
1799  leftSlope = 0;
1800  }
1801  if (rightSlope)
1802  {
1803  delete [] rightSlope;
1804  rightSlope = 0;
1805  }
1806 
1807  if(traceDebug())
1808  {
1809  ossimNotify(ossimNotifyLevel_DEBUG)<<"\nleftMostSample: " << leftMostSample
1810  <<"\nleftMostSampleLine: " << leftMostSampleLine
1811  <<"\n\nrightMostSample: " << rightMostSample
1812  <<"\nrightMostSampleLine: " << rightMostSampleLine
1813 
1814  <<"\n\nfirstLeftSample: " << firstLeftSample
1815  <<"\nfirstRightSample: " << firstRightSample
1816 
1817  <<"\n\nlastLeftSample: " << lastLeftSample
1818  <<"\nlastRightSample: " << lastRightSample
1819 
1820  <<"\n\ntopLine: " << topLine
1821  <<"\nbottomLine: " << bottomLine
1822  <<"\ntotal_lines: " << total_lines
1823 
1824  << "\n\n\ntheVertice[0]: " << theVertice[0]
1825  << "\ntheVertice[1]: " << theVertice[1]
1826  << "\ntheVertice[2]: " << theVertice[2]
1827  << "\ntheVertice[3]: " << theVertice[3]
1828  << "\n\nreturning..." << std::endl;
1829  }
1830 
1831  return true;
1832 }
1833 
1835 {
1836  static const char MODULE[] = "ossimVertexExtractor::writeVertices";
1837 
1838  if (traceDebug()) CLOG << " Entered..." << endl;
1839 
1840  if (!isOpen())
1841  {
1842  // Try to open.
1843  if (!open()) return false;
1844  }
1845 
1846  // Write the points...
1847  theFileStream << "point0.x: " << theVertice[0].x
1848  << "\npoint0.y: " << theVertice[0].y
1849  << "\npoint1.x: " << theVertice[1].x
1850  << "\npoint1.y: " << theVertice[1].y
1851  << "\npoint2.x: " << theVertice[2].x
1852  << "\npoint2.y: " << theVertice[2].y
1853  << "\npoint3.x: " << theVertice[3].x
1854  << "\npoint3.y: " << theVertice[3].y
1855  << endl;
1856 
1857  // Close the file...
1858  close();
1859 
1860  return true;
1861 }
1862 
1863 
1865 {
1867 
1868  if (isOpen()) close();
1869 
1870  theFilename = filename;
1871 }
1872 
1874 {
1875  theAreaOfInterest = rect;
1876 }
1877 
1879 {
1880  return const_cast<ofstream*>(&theFileStream)->is_open();
1881 }
1882 
1884 {
1885  if(isOpen())
1886  {
1887  close();
1888  }
1889 
1891  {
1892  ossimNotify(ossimNotifyLevel_WARN) << "ossimVertexExtractor::open WARNING:"
1893  << "\nOutput file has not been set. Call setFilename() method..."
1894  << std::endl;
1895  return false;
1896  }
1897 
1899 
1900  return theFileStream.good();
1901 }
1902 
1904 {
1905  if (isOpen()) theFileStream.close();
1906 }
1907 
1908 template<class T1>
1910  T1& minValue, ossim_int32& offsetFromStart)
1911 {
1912 
1913  offsetFromStart =0;
1914  ossim_int32 currentOffset = 0;
1915  minValue = *start;
1916  while(start < end)
1917  {
1918  if(*start < minValue)
1919  {
1920 
1921  minValue = *start;
1922  offsetFromStart = currentOffset;
1923  }
1924  ++start;
1925  ++currentOffset;
1926  }
1927 }
1928 
1929 template<class T2>
1931  T2& maxValue, ossim_int32& offsetFromStart)
1932 {
1933 
1934  offsetFromStart =0;
1935  ossim_int32 currentOffset = 0;
1936  maxValue = *start;
1937  while(start < end)
1938  {
1939  if(*start > maxValue)
1940  {
1941  maxValue = *start;
1942  offsetFromStart = currentOffset;
1943  }
1944  ++start;
1945  ++currentOffset;
1946  }
1947 }
ossim_uint32 x
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
void setAreaOfInterest(const ossimIrect &rect)
Class ossimVertexExtractor.
#define CLOG
Definition: ossimTrace.h:23
static const ossimFilename NIL
This was taken from Wx widgets for performing touch and access date stamps.
Definition: ossimFilename.h:40
virtual void setPercentComplete(double percentComplete)
ossimVertexExtractor(ossimImageSource *inputSource=NULL)
ossim_uint32 y
bool valid() const
Definition: ossimRefPtr.h:75
ossim_uint32 height() const
Definition: ossimIrect.h:487
virtual ossim_uint32 getTileHeight() const
Returns the default processing tile height.
#define OSSIM_INT_NAN
const ossimIpt & ul() const
Definition: ossimIrect.h:274
virtual ossimDataObjectStatus getDataObjectStatus() const
T square(T x)
Definition: ossimCommon.h:334
virtual void setProcessStatus(ossimProcessStatus processStatus)
virtual ossim_uint32 getTileWidth() const
Returns the default processing tile width.
virtual void setOutputName(const ossimString &outputName)
ossimConnectableObject * getInput(ossim_uint32 index=0)
returns the object at the specified index.
bool isNull(ossim_uint32 offset) const
RTTI_DEF2(ossimVertexExtractor, "ossimVertexExtractor", ossimSource, ossimProcessInterface)
virtual void setOutputName(const ossimString &filename)
bool isNan() const
Definition: ossimIrect.h:342
const ossimIpt & lr() const
Definition: ossimIrect.h:276
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
virtual bool isOpen() const
ossim_uint32 width() const
Definition: ossimIrect.h:500
const ossimIpt & ur() const
Definition: ossimIrect.h:275
vector< ossimIpt > theVertice
This class defines an abstract Handler which all image handlers(loaders) should derive from...
ossim_int32 y
Definition: ossimIpt.h:142
void getMaxAndIndex(T2 *start, T2 *end, T2 &maxValue, ossim_int32 &offsetFromStart)
void makeNan()
Definition: ossimIrect.h:329
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
ossim_int32 x
Definition: ossimIpt.h:141
std::basic_ofstream< char > ofstream
Class for char output file streams.
Definition: ossimIosFwd.h:47
void getMinAndIndex(T1 *start, T1 *end, T1 &minValue, ossim_int32 &offsetFromStart)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
int ossim_int32
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)