The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Accessing layer properties - scaling an Image Plot

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
easwar Posted - 09/30/2004 : 3:22:15 PM
Hello,

A user recently pointed out that when a matrix is plotted as an Image Plot, we plot the image in an arbitrary/default layer, and so the aspect ratio of the layer does not usually match the aspect ratio of the matrix - the image thus displayed skewed, particularly when the row and col dimensions of the matrix are significantly different.

We will work on addressing this issue from the GUI stand point.

In the mean time we thought providing an OC function to do this will serve as a good example of accessing and manipulating layer properties such as dimension.

Easwar
OriginLab


// This function scales the dimensions of a layer containing an image plot so that
// the aspect ratio of the layer matches the aspect ratio of the matrix containting
// the data.
void ly_scale_image_plot()
{
// Declare active layer as graph layer and check validity
GraphLayer gly = Project.ActiveLayer();
if( !gly )
{
out_str( "Active layer is not a graph layer!\n" );
return;
}

// Loop thru all style holders in layer and check if a matrix image is present
StyleHolder sh;
bool bFound = false;
foreach( sh in gly.StyleHolders )
{
if( IDM_PLOT_MATRIX_IMAGE == sh.GetPlotId() ) bFound = true;
}
if( !bFound )
{
out_str( "Layer does not contain a matrix image plot!\n" );
return;
}

// Loop over all data plots in layer and find the matrix
bFound = false;
DataPlot dp;
string strMatName;
foreach( dp in gly.DataPlots )
{
strMatName = dp.GetDatasetName();
// Try declaring a Matrix object and check validity
MatrixLayer matLy( strMatName );
if( matLy )
{
bFound = true;
break;
}
}
if( !bFound )
{
out_str( "No Matrix data was found in layer!\n" );
return;
}

// Found the matrix object - get its dimensions
int iNumRows, iNumCols;
MatrixLayer matLy( strMatName );
iNumRows = matLy.GetNumRows();
iNumCols = matLy.GetNumCols();
if( ( iNumRows < 2 ) || (iNumCols < 2 ) )
{
out_str( "Too few rows/cols in matrix!\n");
return;
}

// Compute aspect ratio based on matrix dimension
double dMatAspectRatio = 1. * iNumCols / iNumRows;

// Check unit type of layer size - if not in inches, switch to inches temporarily
int iLyUnitType = gly.Dimension.Units.nVal;
// NOTE: You can directly access sub-properties of the layer such a units,
// which is part of Dimension property of the layer, with statements such
// as above. To see what properties are available, one can save a theme file
// from a graph and look a the contents of the theme file.
bool bSwitchedUnits = false;
// If units is not in inches, switch to inches
if( 1 != iLyUnitType )
{
gly.Dimension.Units.nVal = 1;
bSwitchedUnits = true;
}

// Now get the layer dimension properties into a tree
Tree trLyDim;
trLyDim = gly.Dimension;
// NOTE: It is not necessary to copy the layer properties into a tree.
// One can work directly with the layer as in earlier code where layer
// dimension units were changed. This just shows that a tree could be used
// as well.

// Compute layer aspect ratio using layer dimensions
double dLyAspectRatio = trLyDim.Width.dVal / trLyDim.Height.dVal;

// Compare the matrix and layer aspect ratios
double dVariance = abs( dMatAspectRatio - dLyAspectRatio ) / dMatAspectRatio;
if( dVariance < 0.001 )
{
out_str( "Layer aspect ratio is same as matrix aspect ratio!\n" );
return;
}

// Matrix and layer have different aspect ratios - so need to scale layer
if( iNumCols > iNumRows )
trLyDim.Height.dVal = trLyDim.Width.dVal / dMatAspectRatio;
else
trLyDim.Width.dVal = trLyDim.Height.dVal * dMatAspectRatio;

// Set the tree back to apply the dimension change to the layer
gly.Dimension = trLyDim;

// If layer dimension units were switched, then switch back to original settings
if( bSwitchedUnits )
gly.Dimension.Units.nVal = iLyUnitType;
}




The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000