src/GamIO/FrameMaker.cc
/*************************************************************************
**									**
**			FrameMaker Contour Plots			**
**									**
** Author	: Serge Boentges, Scott Smith				**
** Modifications: Switched to C++ and adapted for GAMMA	by SOSI		**
** Description  : Takes a matrix from input along with plot parameters	**
**		  and produces a FrameMaker file containing a contour	**
**		  plot of the matrix.					**
**									**
**		  The original code by Serge was constructed for	**
**		  C-Pheonix which does rapid contour plots inter-	**
**		  actively.  This ended up in function "contour_pts"	**
**		  included below.  The GAMMA FrameMaker contouring	**
**		  "FM_contour" functions, have sacrificed a lot of the	**
**		  speed in Serge's original routine in order to reduce	**
**		  the size of the output FrameMaker mif file while	**
**		  maintaining code clarity and the ability to manip-	**
**		  ulate the contour plot graphically within FM.		**
**									**
** Notes	: There are several routines written to	simplify the	**
**		  code to FM_contour (& also FM_fcontour).  These are	**
**		  listed below with their intended purpose.		**
**									**
**		1. contour_setup - insures that the input parameters	**
**		    are sensible.  If not it determines sensible ones.	**
**		    Also sets up some basic plot parameters.		**
**		2. contour_extr - insures that the chosen contours are	**
**		    reasonable.						**
**		3. thresh_inc - determines the amount to increment in	**
**		    order to reach the next contour level. Used in	**
**		    cases when the levels are internally determined.	**
**		4. contour_levels - determines the contour levels to	**
**		    take.  Done either by an interal calculation based	**
**		    on CLI & CLM values or by an input array of desired	**
**		    contour levels.					**
**		5. FM_same - determines whether two points in an	**
**		    xy-plane should be considered equivalent.		**
**		6. contour_lines - Links together the contour points	**
**		    from "contour_pts" into crude contour lines.	**
**		7. contour_refine - Takes the crude contour lines from	**
**		    "contour_lines" and bridges them into complete	**
**		    contour lines.					**
**		8. contour_refine - Writes all contour lines in a 	**
**		    particular contour level out to the FM file as	**
**		    grouped PolyLines.					**
**		9. group_contours - Groups the contour levels together	**
**		    to form FrameMaker graphics objects			**
**									**
** Note: These routine were redone in mid-June, 1995, by Scott as they	**
**       were pretty messy and bug ridden.  I hope I've improved it.	**
**       Things seem to work fine on the Bruker UXNMR data sets its	**
**       been tested on.  It runs slow though, a 1K x 2K NOESY data set **
**       takes about 10 min on a SPARC 10 to complete, 9 levels with	**
**	 with about 40,000 crude points in the lower contours!		**
**									**
*************************************************************************/


Author : Serge Boentges, Scott Smith
Modifications: Switched to C++ and adapted for GAMMA   by SOSI
Description  : Takes a matrix from input along with plot parameters
and produces a FrameMaker file containing a contour
plot of the matrix.

The original code by Serge was constructed for
C-Pheonix which does rapid contour plots inter
actively.  This ended up in function "contour_pts"
included below.  The GAMMA FrameMaker contouring
"FM_contour" functions, have sacrificed a lot of the
speed in Serge's original routine in order to reduce
the size of the output FrameMaker mif file while
maintaining code clarity and the ability to manip
ulate the contour plot graphically within FM.

Notes  : There are several routines written to simplify the
code to FM_contour (& also FM_fcontour).  These are
listed below with their intended purpose.

1. contour_setup - insures that the input parameters
are sensible.  If not it determines sensible ones.
Also sets up some basic plot parameters.
2. contour_extr - insures that the chosen contours are
reasonable.
3. thresh_inc - determines the amount to increment in
order to reach the next contour level. Used in
cases when the levels are internally determined.
4. contour_levels - determines the contour levels to
take.  Done either by an interal calculation based
on CLI & CLM values or by an input array of desired
contour levels.
5. FM_same - determines whether two points in an
xy-plane should be considered equivalent.
6. contour_lines - Links together the contour points
from "contour_pts" into crude contour lines.
7. contour_refine - Takes the crude contour lines from
"contour_lines" and bridges them into complete
contour lines.
8. contour_refine - Writes all contour lines in a
particular contour level out to the FM file as
grouped PolyLines.
9. group_contours - Groups the contour levels together
to form FrameMaker graphics objects

These routine were redone in mid-June, 1995, by Scott as they
were pretty messy and bug ridden.  I hope I've improved it.
Things seem to work fine on the Bruker UXNMR data sets its
been tested on.  It runs slow though, a 1K x 2K NOESY data set
takes about 10 min on a SPARC 10 to complete, 9 levels with
with about 40,000 crude points in the lower contours!
Author : Serge Boentges Scott Smith Modifications : Switched to C ++ and adapted for GAMMA by SOSI Description : Takes a matrix from input along with plot parameters and produces a FrameMaker file containing a contour plot of the matrix . The original code by Serge was constructed for C - Pheonix which does rapid contour plots inter actively . This ended up in function " contour_pts " included below . The GAMMA FrameMaker contouring " FM_contour " functions have sacrificed a lot of the speed in Serge ' s original routine in order to reduce the size of the output FrameMaker mif file while maintaining code clarity and the ability to manip ulate the contour plot graphically within FM . Notes : There are several routines written to simplify the code to FM_contour ( & also FM_fcontour ) . These are listed below with their intended purpose . 1 . contour_setup - insures that the input parameters are sensible . If not it determines sensible ones . Also sets up some basic plot parameters . 2 . contour_extr - insures that the chosen contours are reasonable . 3 . thresh_inc - determines the amount to increment in order to reach the next contour level . Used in cases when the levels are internally determined . 4 . contour_levels - determines the contour levels to take . Done either by an interal calculation based on CLI & CLM values or by an input array of desired contour levels . 5 . FM_same - determines whether two points in an xy - plane should be considered equivalent . 6 . contour_lines - Links together the contour points from " contour_pts " into crude contour lines . 7 . contour_refine - Takes the crude contour lines from " contour_lines " and bridges them into complete contour lines . 8 . contour_refine - Writes all contour lines in a particular contour level out to the FM file as grouped PolyLines . 9 . group_contours - Groups the contour levels together to form FrameMaker graphics objects These routine were redone in mid - June 1995 by Scott as they were pretty messy and bug ridden . I hope I ' ve improved it . Things seem to work fine on the Bruker UXNMR data sets its been tested on . It runs slow though a 1K x 2K NOESY data set takes about 10 min on a SPARC 10 to complete 9 levels with with about 40 000 crude points in the lower contours!
void contour_setup(const matrix& mx, FMcont& FMCP)
 { 
 int MAXCONTS = 20;				
 if(FMCP.vsize<5 || FMCP.vsize> 27) 		
   FMCP.vsize = 15;				
 if(FMCP.hsize<5 || FMCP.vsize>20)		
   FMCP.hsize = 15;				
 int v_dim = mx.rows();				
 int h_dim = mx.cols(); 			
 if(h_dim < 5) FM_fatality(12);			
 if(v_dim < 5) FM_fatality(13);
 FMCP.vscale = FMCP.vsize/v_dim;		
 FMCP.hscale = FMCP.hsize/h_dim; 		
 double r;					
 double max = -HUGE_VAL;				
 double min = HUGE_VAL;
 for(int i=0; i<v_dim; i++)			
   for(int j=0; j<h_dim; j++)
     {
     r = mx.getRe(i, j);
     if(r > max) max=r;
     if(r < min) min=r;
     }
 if(max == min) FM_fatality(7);			
 FMCP.dmax = max;				
 FMCP.dmin = min;				
 if(FMCP.steps<=0 || FMCP.steps>MAXCONTS) 	
   FMCP.steps = 3;
 if(FMCP.CPN < -1) FMCP.CPN = -1;		
 else if(FMCP.CPN > 1) FMCP.CPN = 1;		
 switch(FMCP.CPN)				
   {						
   case -1:					
     if(FMCP.thresh < FMCP.dmin)		
       {
       FM_error(9);				
       FMCP.thresh = FMCP.dmax;			
       if(FMCP.thresh > 0) FMCP.thresh = 0;
       }
     break;
   case 0:					
     if(FMCP.thresh > FMCP.dmax)		
       {
       FM_error(8);				
       FMCP.thresh = FMCP.dmin;			
       if(FMCP.thresh < 0) FMCP.thresh = 0;
       }
     break;
   case 1:					
     if(FMCP.thresh < 0)			
       FMCP.thresh = -FMCP.thresh;		
     else if(FMCP.thresh == 0 ||
                      FMCP.thresh > FMCP.dmax)
       {
       if(FMCP.dmin <= 0) FMCP.thresh = FMCP.dmax/20;
       else FMCP.thresh = FMCP.dmin;
       FM_error(15);
       }
     break;
   }
 if((FMCP.CLM) && (!FMCP.CLI))			
   FMCP.CLM = 1;				
 if(FMCP.CLM < 1) FMCP.CLM = 1;			
 if(FMCP.CLI < 0) FMCP.CLI = -FMCP.CLI; 	
 else if (FMCP.CLI == 0)			
   {						
   if(FMCP.CPN < 0) FMCP.CLI = 			
         fabs(FMCP.dmin-FMCP.thresh)/FMCP.steps;
   else FMCP.CLI =
          (FMCP.dmax - FMCP.thresh)/FMCP.steps;	
   }
 if(FMCP.debug)
   {
   std::cout << "\n\n\tFrom contour_setup:";
   std::cout << "\n\t   Framemaker Width is " << FMCP.vsize << " cm";
   std::cout << "\n\t   Framemaker Height is " << FMCP.hsize << " cm";
   std::cout << "\n\t   Framemaker Width Scale is " << FMCP.hscale << " cm/point";
   std::cout << "\n\t   Framemaker Height Scale is " << FMCP.vscale << " cm/point";
   std::cout << "\n\t   Input Array Maximum is " << FMCP.dmax;
   std::cout << "\n\t   Input Array Minimum is " << FMCP.dmin;
   std::cout << "\n\t   Requested Number of Contour Steps is " << FMCP.steps;
   std::cout << "\n\t   Lowest Threshold is " << FMCP.thresh;
   std::cout << "\n\t   Contour Level Increment is " << FMCP.CLI;
   std::cout << "\n\t   Contour Level Modifier is " << FMCP.CLM;
   std::cout << "\n\t   Contour Positive/Negative Flag is " << FMCP.CPN;
   }
 }
void contour_setup ( const matrix & mx , FMcont & FMCP ) { int MAXCONTS = 20 ; if ( FMCP . vsize < 5 || FMCP . vsize > 27 ) FMCP . vsize = 15 ; if ( FMCP . hsize < 5 || FMCP . vsize > 20 ) FMCP . hsize = 15 ; int v_dim = mx . rows ( ) ; int h_dim = mx . cols ( ) ; if ( h_dim < 5 ) FM_fatality ( 12 ) ; if ( v_dim < 5 ) FM_fatality ( 13 ) ; FMCP . vscale = FMCP . vsize / v_dim ; FMCP . hscale = FMCP . hsize / h_dim ; double r ; double max = - HUGE_VAL ; double min = HUGE_VAL ; for ( int i = 0 ; i < v_dim ; i ++ ) for ( int j = 0 ; j < h_dim ; j ++ ) { r = mx . getRe ( i , j ) ; if ( r > max ) max = r ; if ( r < min ) min = r ; } if ( max == min ) FM_fatality ( 7 ) ; FMCP . dmax = max ; FMCP . dmin = min ; if ( FMCP . steps <= 0 || FMCP . steps > MAXCONTS ) FMCP . steps = 3 ; if ( FMCP . CPN < -1 ) FMCP . CPN = -1 ; else if ( FMCP . CPN > 1 ) FMCP . CPN = 1 ; switch ( FMCP . CPN ) { case -1 : if ( FMCP . thresh < FMCP . dmin ) { FM_error ( 9 ) ; FMCP . thresh = FMCP . dmax ; if ( FMCP . thresh > 0 ) FMCP . thresh = 0 ; } break ; case 0 : if ( FMCP . thresh > FMCP . dmax ) { FM_error ( 8 ) ; FMCP . thresh = FMCP . dmin ; if ( FMCP . thresh < 0 ) FMCP . thresh = 0 ; } break ; case 1 : if ( FMCP . thresh < 0 ) FMCP . thresh = - FMCP . thresh ; else if ( FMCP . thresh == 0 || FMCP . thresh > FMCP . dmax ) { if ( FMCP . dmin <= 0 ) FMCP . thresh = FMCP . dmax / 20 ; else FMCP . thresh = FMCP . dmin ; FM_error ( 15 ) ; } break ; } if ( ( FMCP . CLM ) && ( ! FMCP . CLI ) ) FMCP . CLM = 1 ; if ( FMCP . CLM < 1 ) FMCP . CLM = 1 ; if ( FMCP . CLI < 0 ) FMCP . CLI = - FMCP . CLI ; else if ( FMCP . CLI == 0 ) { if ( FMCP . CPN < 0 ) FMCP . CLI = fabs ( FMCP . dmin - FMCP . thresh ) / FMCP . steps ; else FMCP . CLI = ( FMCP . dmax - FMCP . thresh ) / FMCP . steps ; } if ( FMCP . debug ) { std :: cout << " \n \n \t " ; std :: cout << " \n \t " << FMCP . vsize << " " ; std :: cout << " \n \t " << FMCP . hsize << " " ; std :: cout << " \n \t " << FMCP . hscale << " " ; std :: cout << " \n \t " << FMCP . vscale << " " ; std :: cout << " \n \t " << FMCP . dmax ; std :: cout << " \n \t " << FMCP . dmin ; std :: cout << " \n \t " << FMCP . steps ; std :: cout << " \n \t " << FMCP . thresh ; std :: cout << " \n \t " << FMCP . CLI ; std :: cout << " \n \t " << FMCP . CLM ; std :: cout << " \n \t " << FMCP . CPN ; } }
FrameMaker Contour Plots
FrameMaker Contour Plots
// Input		mx	: Data matrix //      		FMCP	: Contour plot parameters // Return		  	: Void, argument FMCP may be modified // Note			  	: AUXILIARY FUNCTION FOR FM_contour // Note				: This relates the following entities: //				     horizontal = x = mx.cols() = j //				     vertical   = y = mx.rows() = i // Max. allowed contour levels // Insure plot sizes sensible // Minimum allowed is 5x5 cm // Maximum allowed is 20x27 cm // the default is 15x15 cm // Get array dimensions // & check mx large enough // Minimum 5x5 points allowed // Set vertical scaling (cm/pt) // Set horizon. scaling (cm/pt) // Compute global max & min, // check data vertical spread // Loop over entire matrix // Insure matrix not level! // Store the array maximum // Store the array minimum // Insure [1,20] contours // Insure CPN flag is // either -1, 0, or 1 // Check threshold, i.e. the // initial contour level // Only NEGETIVE contours // Insure catches some data // Threshold below all data // switch to appropriate level // Only POSITIVE contours // Insure catches some data // Threshold above all data // switch to appropriate level // Both POS & NEG contours // Threshold must start off // > 0. // Check CLM vs. CLI input // Cannot set CLI=0 & CLM!=0 // Insure >= 1 CLM // Contour inc. must be > 0 // This flags internal setting // of CLI and forces CLM = 1 // Compute CLI for the  // steps of linear increments