ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Contour on irregular shape
Posted by Alauddin Biswas on Sep-12-2022 12:16
I am using ChartDirector 6.3 for my application (I have commercial dev. & distribution license). I need to draw contour plot for Finite Element stresses on a geometry with irregular boundary (may include triangular mesh or not). Each triangle node has some stress values. The geometry may have one or more holes inside the outer regular or irregular boundaries.

This type of contour is plotted using python and everything is as expected. Python code is something like below;

# plot the filled contour, looping through the materials
            for (i, sig) in enumerate(sigs):
                # create and set the mask for the current material
                mask_array = np.ones(len(self.section.elements), dtype=bool)
                mask_array[self.material_groups[i].el_ids] = False

                # plot the filled contour
                trictr = ax.tricontourf(triang, sig, v, cmap=cmap, norm=norm)

I tried with scattered contour, as shown in ChartDirector example. But, in am not getting it  as expected. It is filling the non-data areas as well. My development platform is C++ with Win32 API. I am rendering/drawing the Chart bitmap like similar to MFC example.

I am trying to attach several .png files showing both Python and ChartDirector plotted figures. I am also attaching an excel file with sample data.

I would appreciate for any help from you, regarding this.

With regards,

Alauddin Biswas

205.32 Kb

  Re: Contour on irregular shape
Posted by Peter Kwan on Sep-13-2022 02:28
Hi Alauddin,

I think the key is to apply a "mask" to the chart to mask out the unwanted parts. In the Python code in your message, it seems there is a "mask array" to define the mask.

In ChartDirector, there is no built-in support for a general "mask", but you can simply draw white shapes over the unwanted part to cover them.

For your first chart, the unwanted part can be covered by two rectangles.

Your second chart is more complicated, as the unwanted part consists of a rounded rectangle in the center, and 4 rounded corners. All of them needs to be drawn as polygons. (A rounded edge can be approximated as many short line segments join together. This is how ChartDirector and most computer graphics program draw all the curve shapes internally.) In general, you can always use polygons to draw the mask shapes. Polygons can be drawn using DrawArea.polygon, or (in ChartDirector 7.0) DrawArea.polyShape.

I noted that your attached chart seems to have some triangulation. If you also have triangulation of the mask region, you can simply paint those triangles white. (Triangles can be painted as polygons with 3 vertices.)

One issue of drawing over the unwanted part is that it will cover everything, including the grid lines. You may consider to configure the original chart to have no grid lines at all (set the grid line colors to transparent). If you do need to grid lines, you can draw them back after drawing the mask. The position of the grid lines can be obtained using Axis.getTicks.

Best Regards
Peter Kwan

  Re: Contour on irregular shape
Posted by Alauddin Biswas on Sep-13-2022 04:59
Hi Peter,
Thank you for your quick reply. I will try it according to your suggestions. It seems, it will be little bit difficult for me since, in some cases, the outside perimeter will be very irregular and generic.

In opposite way, is it possible to clip(making visible) only the required portion of the plot area using closed polylines ? I know vertices of all the closed polylines defining outside perimeter and the inside holes. Please advise me about it since it will be simpler and generic for me.

With best regards,


  Re: Contour on irregular shape
Posted by Peter Kwan on Sep-13-2022 11:20
Hi Alauddin,

If you know the polylines of the perimeter of your shape, in ChartDirector 7, you can easily create the mask by adding and extra containing rectangle to the shape. For your case, you can use the plot area rectangle as the containing rectangle. It is possible in ChartDirector 6 too, but more difficult.

ChartDirector uses the "even-odd rule" to determine what is the shape. (Wiki has an explanation of what is the "even-odd" rule.) The ChartDirector 7 DrawArea.polyShape allows you to define a shape as a set of polylines. The even-odd rule means that adding an containing rectangle (the plot area rectangle) to your shape will create a rectangle with your shape cut out. This is then your mask.

ChartDirector 6 DrawArea.polygon only allows one polyline, so you have to join your multiple polylines and the containing rectangle into a single polyline using "zero-width bridges". It is hard to explain in words, so I attached an image to illustrate.

The shape on the left side contains 3 concentric squares. According to the even-odd rule, it is a square with the inner square frame cut out.

The shape on the right side is created by joining the 3 squares. It is by joining the 3 squares into one polyline. If these two bridges are zero-width, that is, the two lines forming the bridge has identical coordinates, they would not be visible when the shape is filled.

I have not tried myself, but I think for a general shape with multiple polylines, you can join multiple polylines at random positions into one polyline and it will still work. ChartDirector 6 can handle self-overlapping polylines, so as long as the bridge is zero width, it should not be visible.

Best Regards
Peter Kwan

  Re: Contour on irregular shape
Posted by Alauddin Biswas on Sep-13-2022 14:10
Hi Peter,
Again, thank you for your detail explanations. I understand something like, using Chart Director 7, I can use plot area as containing rectangle and my outside perimeter polyline (closed) as another closed path. The region between plot area rectangle and my outside perimeter polyline path will be the mask (cyan below). After creating this mask, I can hide this region using white color (or any other color I like). Am I right in this understanding ? Is it like below (cyan is the mask between two paths - created in BlueBeam Revu) ? After that, if I want, I need to draw the grid lines.

For grid lines, can I create a plot without contour (white background with grid lines only)) and copy in a separate image and overlay on the final image ?

In my understanding, for holes inside my outside perimeter, I can add one or more white (or different color) closed polylines, as necessary. In the second figure, I added one yellow, one white and one blue hole. Good thing for me is that I know vertices for outside perimeter (counter clockwise) and for all the holes (clockwise). Is it possible like this ?

I bought Chart Director 6.1 several years ago and I found in your licensing policy that I am eligible for one major version upgrade for free. Your website says something like version  ?.x. In my case, is it 7.x or 7.1 or something different ? Please let me know.

With best regards,


  Re: Contour on irregular shape
Posted by Peter Kwan on Sep-13-2022 18:38
Hi Alauddin,

If on the date of purchasing the ChartDirector license, the ChartDirector was of version 6, then your license key will work for ChartDirector version 7.x as well. You can upgrade to ChartDirector 7.0, then 7.1, 7.2, etc.. You do not need to purchase any upgrade until ChartDirector version 8.

If you have holes inside your outer parameter (such as the "Stress Contour Plot" in your first message), you can add this to the poly shape, that is, the shape will contain the plot area rectangle, outer perimeter, and the perimeter of the holes. When you fill it, it will fill the region between the plot area rectangle and the outside parameter, and also the region inside the holes. With this method, the holes and must be of the same color as the mask.

If you want the holes to be of different colors, then you can just draw the holes as separate polygons.

For the grid lines, you can use DrawArea.line to add them back. You do not need to use another chart. It is like (in C++):

... Create contour chart as usual ...

// Obtain drawarea for custom drawings. Note that the drawarea uses pixel coordinates.
// You may need to use c->getXCoor and c->getYCoor to convert data values to pixel coordinates.
DrawArea *d = c->makeChart();

... create the poly shape array to be used as a mask ....

d->polyShape(IntArray(myPolyShapeArray, myPolyShapeArraySize), myMaskColor);

// Draw the grid lines after applying the mask
PlotArea *p = c->getPlotArea();
int plotAreaTop = p->getTopY();
int plotAreaBottom = p->getBottomY();

// Draw the grid lines for the x-axis
DoubleArray ticks = c->xAxis()->getTicks();
for (int i = 0; i < ticks.len; ++i) {
    int xCoor = c->getXCoor(ticks[i]);
    d->line(xCoor, plotAreaTop, xCoor, plotAreaBottom, 0xcccccc);

.... similarly, draw the grid lines for the y-axis ....

Best Regards
Peter Kwan

  Re: Contour on irregular shape
Posted by Alauddin Biswas on Sep-13-2022 23:21
Hi Peter,
Thank you. I will download the latest version of ChartDirector (v 7.0) and will follow your suggestions to achieve my goal. After that, I will let you know about the final plot I will be receiving.

With best regards,