Correct way to scale data

Hi everybody !
I’m still deal with a box of 256x256x256 cell , and polydata (vtk file containing 5 point) representing a polymer . I would like to give a scaling factor , I’ve tried using transform selecting just scale but the data set move from the original position , I would like to scale but around the same center point … how is the correct procedure ?

Funny, I thought I just saw a reply from Ken Moreland. Anyway, use the Transform filter. I bet the reason you are seeing the data move from the original position is that the Tranform filter scales around 0,0,0. The center of your data probably isn’t at 0.0,0. Alternatively, run the Transform filter three times. 1) translate 0,0,0 to the center of your data, 2) scale, 3) translate your data back where you want it.

@wascott is correct. Currently the only way to scale around the center of the data is to perform these three transformations. To make this easier, I’ve attached a Python script that will do these three transformations on the active data set for you. You can download this script and then bind it to a macro if you like. The script arbitrarily scales by a factor of 5. You can change that in the script or later change the scale in the middle transform.

You should be able to download the Python script here: (584 Bytes)

In case that does not work, here are the contents of the script:

scale_factor = 5

indata = GetActiveSource()

bounds = indata.GetDataInformation().GetBounds()
center = ((bounds[0] + bounds[1])/2,
          (bounds[2] + bounds[3])/2,
          (bounds[4] + bounds[5])/2)

transform_to_center = Transform()
transform_to_center.Transform.Translate = [-center[0], -center[1], -center[2]]

scale = Transform()
scale.Transform.Scale = [scale_factor, scale_factor, scale_factor]

transform_from_center = Transform()
transform_from_center.Transform.Translate = [center[0], center[1], center[2]]


Hey @Kenneth_Moreland, That is a really sweet script! Thanks for making it!

thank you very much !! the problem is how to load it on paraview ? Using custom filter ? or where ?

If you just want to run the filter one time, you can open up the Python Shell (menu View -> Python Shell) and then click the Run Script button.

If you want to bind the script to a macro to make it easy to run lots of times, you can do so with the menu option Macros -> Add New Macro.... When you load in that Python script, it will be listed in the macros toolbar and in the Macros menu.

There is a tutorial that hangs off the Help menu. Help/ Sandia National Labs Tutorials/ ParaView and Python. The section you want is Running Scripts and Macros. The Trace Recorder section explains how to have ParaView generate scripts for you.

Thanks !! great script ! works like a charm :slight_smile:

Hey y’all,

I know this is a little old, but I wanted to add this for completeness. I was recently trying scale objects in place in a pvbatch script and found that the object was not translating to the center and back. Eventually I determined that the line:

bds = rotationFilt.GetDataInformation.GetBounds()

was returning [1e299,…,1e299].

To return the proper boundaries I simply had to add:

bds = rotationFilt.GetDataInformation.GetBounds()

This fixed the translation issue, and my overall scaling in place issue. Hope this might save somebody 30 minutes.