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

Message ListMessage List     Post MessagePost Message

  Drawing a triangular mesh
Posted by Adil on Nov-04-2021 18:54
Hi,

I'm new to ChartDirector. Indeed, I got my developer licence yesterday.

I would like to overlay a TIN (Triangular Irregular Network) which is a 2D triangular mesh on the top of a contour chart for post-processing an engineering Finite Element application.

Because there is no direct way to plot a TIN in the library, there are two workarounds:

1) First, by plotting all the individual edges connecting two points of the TIN by calling the addLine method.

2) Alternatively, by calling the addLineLayer of an XYChart chart that will plot all the TIN edges.

Which method do you advise for greater performance? The TIN objects can typically have a size of 100000 edges for the target applications.

Thanks,
Adil

  Re: Drawing a triangular mesh
Posted by Peter Kwan on Nov-05-2021 11:07
Hi Adil,

For 100000 edges, I think a third method DrawArea.line can be considered.

I am not sure which programming langauge you are using, so I just use C# as an example. If you need me to translate the code to another programming language, please let me know.

The code is like:

.... create the contour chart as usual ....

// Draw the chart
// makeChart3 in C#, makeChart in C++
DrawArea d = c.makeChart3();

// Use DrawArea.line to add lines over the chart
for (int i = 0; i < edgeCount; ++i) {
    ... obtain end points (x1, y1) and (x2, y2) of an edge ...

    // Draw  a line with the dark grey color (0x444444) and line width = 1
    // The getXCoor/getYCoor is to convert the data coordinates to pixel coordinates
    d.line(c.getXCoor(x1), c.getYCoor(y1), c.getXCoor(x2), c.getYCoor(y2), 0x444444, 1);
}


The addLineLayer can also be fast if you can pre-processed the edges into continuous lines. That is, instead of edge A to B, edge B to C, edge C to D, you can connect them to become one line A to B to C to D. In this way, there result will be a smaller number of lines, each with many edges.

Regards
Peter Kwan

  Re: Drawing a triangular mesh
Posted by Adil on Nov-05-2021 16:52
Hi Peter,

Thanks for your suggestion. My project is in C++ but I know C# too.
I'll test your method and come back to you if there are further issues.

Kind Regards,
Adil

  Re: Drawing a triangular mesh
Posted by Adil on Sep-10-2022 21:43
Attachments:
Hi Peter,

As a follow-up to this question, the solution you have suggested is working fine as shown in the first attached figure. The mesh is overlying the 2D contour map as expected.

This is fine for a batch generation of the plot as I did previously. Now I'm working on doing the same job from within a windows (MFC-based) program, thus enabling the user to interactively zoom in and out the plot.

Using the CD7 CChartViewer control class worked fine for me, except that when zooming in the mesh layer remains visible outside the plot area. It seems that stuff in the DrawArea object is not synchronized with those in the ContourLayer object. The second attached figure shows the problem.

Any idea how to fix it?

Thanks,
Adil
figure1.gif
figure2.gif

  Re: Drawing a triangular mesh
Posted by Peter Kwan on Sep-12-2022 03:56
Hi Adil,

May be try DrawArea.setClipRect. It is like:

// Set the clip rectangle to the plot area
PlotArea p = c.getPlotArea();
d.setClipRect(p.getLeftX(), p.getTopY(), p.getRightX(), p.getBottomY());

// Lopp to draw the lines
for (....) {
....
}

// Remove the clip rectangle by setting it to the entire chart
d.setClipRect(0, 0, c.getWidth(), c.getHeight());

Best Regards
Peter Kwan

  Re: Drawing a triangular mesh
Posted by Adil on Sep-12-2022 05:42
Hi Peter,

Perfect.

Thank you very much.
Adil

  Re: Drawing a triangular mesh
Posted by Adil on Nov-05-2021 16:54
Hi Peter,

Thanks for your suggestion. My project is in C++ but I know C# too.
I'll test your method and come back to you if there are further issues.

Kind Regards,
Adil