如何使用 Conrec 组装轮廓线的连续点数组

发布于 2024-10-29 00:29:45 字数 1017 浏览 6 评论 0原文

我有一个 Conrec 噩梦。我正在尝试使用 Conrec 在 ActionScript 中实现轮廓线。我已经查看了 java 和 javascript 实现,但仍然陷入困境。这些可以在这里找到:http://paulbourke.net/papers/conrec/

Conrec 将获取网格数据并组装连续的轮廓线。问题在于它不一定以连续的方式绘制这些线。例如,它将绘制 A->B,然后 C->B,然后 C->D,而不是 A、B、C、D 等

。javascript 实现似乎正在考虑这一点并序列化指令到绘制点数组中。这也是我最终想要实现的目标。也就是说,它从核心 Conrec 逻辑获取指令(例如:A->B、C->B、C->D 等)并将其组织成 A、B、C、D 系列。我认为它还会将系列作为多维数组返回以容纳折线(例如:[[A, B, C, D], [E, F, G]])。最后一个功能是我需要在 Actionscript 中执行的操作。

最后一部分是我陷入困境的地方。暂时忽略Conrec(我已经放弃寻找Actionscript实现),我如何将这些指令组织成串行点的集合?当 Conrec 给我“从 X->Y 绘制点”时,我如何首先检查 X 或 Y 是否已经在系列中,并将 X 或 Y(以不在系列中的为准)附加到系列中?如果两者都不在系列中,则开始一个以 X、Y 作为起始集的新系列。然后检查所有现有系列的后续说明,并连接系列是否现在在同一点开始和停止?另外,我需要能够允许一系列自行关闭(例如:A、B、C、A)——一个循环(这可能吗?!)。

我希望这是有道理的。我不确定除了“串联”之外是否有一个技术术语来描述我想做的事情。我也希望有人已经使用 Conrec 完成了这项工作,并且可以给我一些指导。

与此同时,我将继续努力,看看我是否能想出一些东西,但我对自己的能力没有信心。我真的很感谢一些资深人士或专业人士的建议。

附: 如果您知道从网格数据绘制轮廓线的另一种方法,我愿意接受替代方案。但我必须能够在 Actionscript 中实现它。

I have a Conrec nightmare. I am trying to implement contour lines in ActionScript using Conrec. I have looked at both the java and javascript implementation and am still stuck. These are found here: http://paulbourke.net/papers/conrec/

Conrec will take grid data and assemble continuous contour lines. The problem is that it does not necessarily draw those lines in a continuous fashion. For example, it will draw A->B and then C->B and then C->D instead of A, B, C, D, etc.

The javascript implementation seems to be accounting for this and serializing the instructions into an array of draw points. Which is what I too want to accomplish in the end. That is it takes the instructions from the core Conrec logic (eg: A->B, C->B, C->D, etc) and organizes it into an A, B, C, D series. I think it will also return the series as a multi-dimensional array to accommodate broken lines (eg: [[A, B, C, D], [E, F, G]]). This last functionality is what I need to do in Actionscript.

This last part is where I am stuck. Ignore Conrec for now (I have given up on finding an Actionscript implementation), how can I organize these instructions into a collection of serial points? When Conrec gives me "draw point from X->Y" how can I first check if X or Y are already in a series and append either X or Y (whichever is not in the series) into the series? AND if neither are in the series, start a NEW series with X, Y as the starting set. Then check subsequent instructions against all existing series and connect series if they now start and stop on the same point? Also, I need to be able to allow for a series to close itself (eg: A, B, C, A) -- a loop (is that even possible?!).

I hope this makes sense. I'm not sure if there is a technical term for what I want to do beyond "concatenation". I also hope someone out there has done this with Conrec and can give me some pointers.

In the meantime, I am going to continue to plug away at this and see if I can come up with something but I am not confident in my abilities. I would really be thankful for some veteran or professional advice.

PS:
If you know another way to draw contour lines from grid data, I am open to alternatives. But I have to be able to implement it in Actionscript.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凉城 2024-11-05 00:29:46

好的,这是我第一次尝试完成我需要做的事情。我对结果不是很满意,但它似乎有效。

package {
  import flash.display.Sprite;

  public class lineSeriesPointConcat extends Sprite {
    public function lineSeriesPointConcat() {
      init();
    }
    //directions [X -> Y]
    //case 1: both counterclockwise, result is counterclockwise
    private var case1:Array = [
      ["G1", "F1"], 
      ["F1", "E1"], 

      ["D1", "C1"],
      ["C1", "B1"],
      ["B1", "A1"], 

      ["E1", "D1"], //link
      ["G1", "A1"] //loop
    ];

    //case 2: clockwise, counterclockwise, result is clockwise
    private var case2:Array = [
      ["E2", "F2"], 
      ["F2", "G2"], 

      ["D2", "C2"], 
      ["C2", "B2"], 
      ["B2", "A2"], 

      ["E2", "D2"], //link
      ["G2", "A2"] //loop
    ];

    //case 3: both clockwise, result is clockwise
    private var case3:Array = [
      ["E3", "F3"], 
      ["F3", "G3"], 

      ["A3", "B3"], 
      ["B3", "C3"], 
      ["C3", "D3"], 

      ["E3", "D3"], //link
      ["G3", "A3"] //loop
    ];

    //case 4: counterclockwise, clockwise, result is clockwise
    private var case4:Array = [
      ["G4", "F4"], 
      ["F4", "E4"], 

      ["A4", "B4"], 
      ["B4", "C4"], 
      ["C4", "D4"], 

      ["E4", "D4"], //link
      ["G4", "A4"] //loop
    ];


    private var collectedSeries:Array = [];

    private function init():void {
      var directions:Array = case1.concat(case2.concat(case3.concat(case4)));
      for each (var direction:Array in directions) {
        connect(direction[0], direction[1]);
      }
      trace ("final series:\n\t" + collectedSeries.join("\n\t"));
    }

    private function connect(from:String, to:String):void {
      var series:Array;
      var seriesStart:String;
      var seriesEnd:String;
      var seriesIndex:int;
      var n:int = collectedSeries.length;
      var i:int;
      for (i = 0; i < n; i++) {
        series = collectedSeries[i];
        seriesStart = series[0];
        seriesEnd = series[series.length - 1];

        if (seriesStart == to) {
          seriesStart = from;
          series.unshift(from);
          break;
        } else if (seriesStart == from) {
          seriesStart = to;
          series.unshift(to);
          break;
        } else if (seriesEnd == to) {
          seriesEnd = from;
          series.push(from);
          break;
        } else if (seriesEnd == from) {
          seriesEnd = to;
          series.push(to);
          break;
        }
      }

      if (i == n) {
        //this is a new series segment
        series = [from, to];
        seriesStart = from;
        seriesEnd = to;
        collectedSeries.push(series);
      }

      for (var j:int = 0; j < n; j++) {
        var compareSeries:Array = collectedSeries[j];
        if (compareSeries == series) {
          //don't compare the series to itself.
          continue;
        }
        var compSeriesStart:String = compareSeries[0];
        var compSeriesEnd:String = compareSeries[compareSeries.length - 1];
        if (compSeriesStart == compSeriesEnd) { 
          //this series loops on itself, it will not concatenate further
          continue;
        }
        if (compSeriesStart == seriesEnd) {
          trace ("case 1");
          series = series.concat(compareSeries.slice(1));
        } else if (compSeriesStart == seriesStart) {
          trace ("case 2");
          series = compareSeries.reverse().concat(series.slice(1));
        } else if (compSeriesEnd == seriesStart) {
          trace ("case 3");
          series = compareSeries.concat(series.slice(1));
        } else if (compSeriesEnd == seriesEnd) {
          trace ("case 4");
          series = compareSeries.concat(series.reverse().slice(1));
        } else {
          //no linkage between these two series
          continue;
        }
        collectedSeries[i] = series; //replace one of the two segements
        collectedSeries.splice(j, 1); //splice out the other
        break;
      }
      trace ("series: " + series + (i == n ? " new" : ""));
    }
  }
}

这将给出以下结果:

A1,G1,F1,E1,D1,C1,B1,A1

G2,A2,B2,C2,D2,E2,F2,G2

G3,A3,B3,C3,D3,E3,F3 ,G3

G4,A4,B4,C4,D4,E4,F4,G4

我仍然非常感谢我能得到的任何建议/反馈。 没有人使用Conrec吗?!

编辑:哎呀!我原来的 splice() 有一个错误!对不起!现已修复

Ok, here is my first attempt at getting what I need done. I am not terribly happy with the result, but it seems to work.

package {
  import flash.display.Sprite;

  public class lineSeriesPointConcat extends Sprite {
    public function lineSeriesPointConcat() {
      init();
    }
    //directions [X -> Y]
    //case 1: both counterclockwise, result is counterclockwise
    private var case1:Array = [
      ["G1", "F1"], 
      ["F1", "E1"], 

      ["D1", "C1"],
      ["C1", "B1"],
      ["B1", "A1"], 

      ["E1", "D1"], //link
      ["G1", "A1"] //loop
    ];

    //case 2: clockwise, counterclockwise, result is clockwise
    private var case2:Array = [
      ["E2", "F2"], 
      ["F2", "G2"], 

      ["D2", "C2"], 
      ["C2", "B2"], 
      ["B2", "A2"], 

      ["E2", "D2"], //link
      ["G2", "A2"] //loop
    ];

    //case 3: both clockwise, result is clockwise
    private var case3:Array = [
      ["E3", "F3"], 
      ["F3", "G3"], 

      ["A3", "B3"], 
      ["B3", "C3"], 
      ["C3", "D3"], 

      ["E3", "D3"], //link
      ["G3", "A3"] //loop
    ];

    //case 4: counterclockwise, clockwise, result is clockwise
    private var case4:Array = [
      ["G4", "F4"], 
      ["F4", "E4"], 

      ["A4", "B4"], 
      ["B4", "C4"], 
      ["C4", "D4"], 

      ["E4", "D4"], //link
      ["G4", "A4"] //loop
    ];


    private var collectedSeries:Array = [];

    private function init():void {
      var directions:Array = case1.concat(case2.concat(case3.concat(case4)));
      for each (var direction:Array in directions) {
        connect(direction[0], direction[1]);
      }
      trace ("final series:\n\t" + collectedSeries.join("\n\t"));
    }

    private function connect(from:String, to:String):void {
      var series:Array;
      var seriesStart:String;
      var seriesEnd:String;
      var seriesIndex:int;
      var n:int = collectedSeries.length;
      var i:int;
      for (i = 0; i < n; i++) {
        series = collectedSeries[i];
        seriesStart = series[0];
        seriesEnd = series[series.length - 1];

        if (seriesStart == to) {
          seriesStart = from;
          series.unshift(from);
          break;
        } else if (seriesStart == from) {
          seriesStart = to;
          series.unshift(to);
          break;
        } else if (seriesEnd == to) {
          seriesEnd = from;
          series.push(from);
          break;
        } else if (seriesEnd == from) {
          seriesEnd = to;
          series.push(to);
          break;
        }
      }

      if (i == n) {
        //this is a new series segment
        series = [from, to];
        seriesStart = from;
        seriesEnd = to;
        collectedSeries.push(series);
      }

      for (var j:int = 0; j < n; j++) {
        var compareSeries:Array = collectedSeries[j];
        if (compareSeries == series) {
          //don't compare the series to itself.
          continue;
        }
        var compSeriesStart:String = compareSeries[0];
        var compSeriesEnd:String = compareSeries[compareSeries.length - 1];
        if (compSeriesStart == compSeriesEnd) { 
          //this series loops on itself, it will not concatenate further
          continue;
        }
        if (compSeriesStart == seriesEnd) {
          trace ("case 1");
          series = series.concat(compareSeries.slice(1));
        } else if (compSeriesStart == seriesStart) {
          trace ("case 2");
          series = compareSeries.reverse().concat(series.slice(1));
        } else if (compSeriesEnd == seriesStart) {
          trace ("case 3");
          series = compareSeries.concat(series.slice(1));
        } else if (compSeriesEnd == seriesEnd) {
          trace ("case 4");
          series = compareSeries.concat(series.reverse().slice(1));
        } else {
          //no linkage between these two series
          continue;
        }
        collectedSeries[i] = series; //replace one of the two segements
        collectedSeries.splice(j, 1); //splice out the other
        break;
      }
      trace ("series: " + series + (i == n ? " new" : ""));
    }
  }
}

This will give the following results:

A1,G1,F1,E1,D1,C1,B1,A1

G2,A2,B2,C2,D2,E2,F2,G2

G3,A3,B3,C3,D3,E3,F3,G3

G4,A4,B4,C4,D4,E4,F4,G4

I would still really appreciate any advice/feedback I can get. Does no one use Conrec?!

Edit: woops! I had a bug with the original splice()! sorry! fixed now

迷荒 2024-11-05 00:29:46

我刚刚将ConRec移植到Actionscript3并且似乎工作正常,我还没有彻底测试它,
但它按照我期望的方式绘制了我的轮廓。如果愿意的话请尝试一下,我很好奇它是否是正确的端口。它在这里:

http://www.jvanderspek.com/DEV/ConRec/ConRec.as< /a>

I just ported ConRec to Actionscript3 and seems to work fine, I haven't tested it thoroughly,
but it draws my contours the way I expect. Try it out if you will, I'm curious if it's a correct port. it's here:

http://www.jvanderspek.com/DEV/ConRec/ConRec.as

单身情人 2024-11-05 00:29:46

好的,Flash 可能有更好的替代方案。我刚刚找到这个链接,它看起来令人印象深刻。如果这有效,它就可以消除原来的问题...

隔离包对于 ActionScript 3

Ok, so there may be a much better alternative for Flash. I just found this link and it looks impressive. If this works, it obviates the original problem...

isolining package for ActionScript 3

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文