File: AdaptiveSkeletonClimbing2.cpp

package info (click to toggle)
libwildmagic 5.17%2Bcleaned1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 90,124 kB
  • sloc: cpp: 215,940; csh: 637; sh: 91; makefile: 40
file content (186 lines) | stat: -rw-r--r-- 5,386 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// Geometric Tools, LLC
// Copyright (c) 1998-2014
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
//
// File Version: 5.5.1 (2011/07/26)

#include "AdaptiveSkeletonClimbing2.h"
#include "Climb2D.h"

WM5_CONSOLE_APPLICATION(AdaptiveSkeletonClimbing2);

int AdaptiveSkeletonClimbing2::msData[81] =
{
    +1, -1, -1, +1, -1, -1, +1, -1, +1,
    +1, +1, +1, +1, +1, +1, +1, +1, +1,
    -1, -1, +1, +1, +1, +1, -1, -1, -1,
    -1, -1, +1, +1, +1, +1, -1, -1, -1,
    -1, -1, +1, +1, +1, +1, -1, -1, -1,
    +1, -1, -1, -1, -1, -1, -1, +1, +1,
    -1, -1, +1, -1, -1, -1, -1, -1, +1,
    +1, +1, +1, -1, -1, -1, +1, -1, -1,
    -1, +1, -1, +1, +1, +1, -1, +1, +1
};

ImageRGB82D* AdaptiveSkeletonClimbing2::msColor = 0;

//----------------------------------------------------------------------------
AdaptiveSkeletonClimbing2::AdaptiveSkeletonClimbing2 ()
    :
    ConsoleApplication("SampleImagics/AdaptiveSkeletonClimbing2")
{
    msColor = new0 ImageRGB82D(257, 257);
}
//----------------------------------------------------------------------------
AdaptiveSkeletonClimbing2::~AdaptiveSkeletonClimbing2 ()
{
    delete0(msColor);
}
//----------------------------------------------------------------------------
void AdaptiveSkeletonClimbing2::Test0 ()
{
    int* data = new1<int>(81);
    memcpy(data, msData, 81*sizeof(int));

    Climb2D climb(3, data);

    int numVertices, numEdges;
    Vector2f* vertices = 0;
    Climb2D::Edge2* edges = 0;
    climb.ExtractContour(0.0f, -1, numVertices, vertices, numEdges, edges);
    climb.MakeUnique(numVertices, vertices, numEdges, edges);

    std::ofstream outFile("vedata0.txt");
    int i;
    for (i = 0; i < numVertices; ++i)
    {
        Vector2f& vertex = vertices[i];
        outFile << i << " " << vertex[0] << " , " << vertex[1] << std::endl;
    }
    outFile << std::endl;

    for (i = 0; i < numEdges; ++i)
    {
        Climb2D::Edge2& edge = edges[i];
        outFile << i << " " << edge.first << " " << edge.second << std::endl;
    }

    delete1(vertices);
    delete1(edges);
}
//----------------------------------------------------------------------------
void AdaptiveSkeletonClimbing2::Test1 ()
{
    ImageInt2D image(257, 257);
    image = (Eint)0;

    int x, y;
    for (y = 32; y < 224; ++y)
    {
        for (x = 64; x < 192; ++x)
        {
            image(x, y) = 100;
        }
    }

    ImageInt2D blur(257, 257);
    blur = (Eint)0;

    int i;
    for (i = 1; i <= 8; ++i)
    {
        for (y = 0; y < 257; ++y)
        {
            for (x = 0; x < 257; ++x)
            {
                if (image(x, y) != 0)
                {
                    int sum = 0;
                    for (int dy = -1; dy <= 1; ++dy)
                    {
                        for (int dx = -1; dx <= 1; ++dx)
                        {
                            sum += image(x+dx, y+dy);
                        }
                    }
                    blur(x, y) = sum/9;
                }
            }
        }
        image = blur;
    }

    blur.Save("blur.im");

    const int N = 8;
    int* data = new1<int>(blur.GetQuantity());
    memcpy(data, blur.GetData(), blur.GetQuantity()*sizeof(int));

    Climb2D climb(N, data);

    int numVertices, numEdges;
    Vector2f* vertices = 0;
    Climb2D::Edge2* edges = 0;
    climb.ExtractContour(75.5f, 0, numVertices, vertices, numEdges, edges);
    climb.MakeUnique(numVertices, vertices, numEdges, edges);

    std::ofstream outFile("vedata1.txt");
    for (i = 0; i < numVertices; ++i)
    {
        Vector2f& vertex = vertices[i];
        outFile << i << " " << vertex[0] << " , " << vertex[1] << std::endl;
    }
    outFile << std::endl;

    for (i = 0; i < numEdges; ++i)
    {
        Climb2D::Edge2& edge = edges[i];
        outFile << i << " " << edge.first << " " << edge.second << std::endl;
    }

    for (i = 0; i < blur.GetQuantity(); ++i)
    {
        unsigned int gray = (unsigned int)(255.0f*blur[i]/100.0f);
        (*msColor)[i] = (gray | (gray << 8) | (gray << 16));
    }

    // Draw vertices.
    for (i = 0; i < numVertices; ++i)
    {
        Vector2f& vertex = vertices[i];
        x = (int)vertex[0];
        y = (int)vertex[1];
        (*msColor)[x + 257*y] = 0x00FF0000;
    }

    // Draw edges.
    for (i = 0; i < numEdges; i++)
    {
        Climb2D::Edge2& edge = edges[i];
        int x0 = (int)vertices[edge.first][0];
        int y0 = (int)vertices[edge.first][1];
        int x1 = (int)vertices[edge.second][0];
        int y1 = (int)vertices[edge.second][1];
        Line2D(x0, y0, x1, y1, SetPixel);
    }

    msColor->Save("color.im");

    delete1(vertices);
    delete1(edges);
}
//----------------------------------------------------------------------------
void AdaptiveSkeletonClimbing2::SetPixel (int x, int y)
{
    (*msColor)(x, y) = 0x00FF0000;
}
//----------------------------------------------------------------------------
int AdaptiveSkeletonClimbing2::Main (int, char**)
{
    Test0();
    Test1();
    return 0;
}
//----------------------------------------------------------------------------