Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
cdo
Commits
b2d9b24e
Commit
b2d9b24e
authored
Nov 10, 2017
by
Uwe Schulzweida
Browse files
Merge declaration and initialization.
parent
5cac182c
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/kdtreelib/kdtree.h
View file @
b2d9b24e
...
...
@@ -58,6 +58,7 @@ typedef long kdata_t;
#define KD_MAX_DIM 3
typedef
struct
kd_point
{
kdata_t
point
[
KD_MAX_DIM
];
size_t
index
;
...
...
@@ -73,7 +74,6 @@ int qcmp(struct kd_point *a, struct kd_point *b, int axis)
return
ret
;
}
/*!
* \struct kdNode
* \brief kd-tree node structure definition
...
...
@@ -81,9 +81,9 @@ int qcmp(struct kd_point *a, struct kd_point *b, int axis)
typedef
struct
kdNode
{
struct
kdNode
*
left
;
/*!<the left child of the tree node */
struct
kdNode
*
right
;
/*!<the right child of the tree node */
kdata_t
location
[
KD_MAX_DIM
];
/*!<vector to the node's location */
kdata_t
min
[
KD_MAX_DIM
];
/*!<vector to the min coordinates of the hyperrectangle */
kdata_t
max
[
KD_MAX_DIM
];
/*!<vector to the max coordinates of the hyperrectangle */
kdata_t
location
[
KD_MAX_DIM
];
/*!<vector to the node's location */
int
split
;
/*!<axis along which the tree bifurcates */
size_t
index
;
/*!<optional index value */
}
kdNode
;
...
...
@@ -102,7 +102,7 @@ typedef struct resItem {
* \brief priority queue (min-max heap)
*/
typedef
struct
pqueue
{
struct
resItem
**
d
;
/*!<pointer to an array of result items */
struct
resItem
**
d
;
/*!<pointer to an array of result items */
size_t
size
;
/*!<current length of the queue */
size_t
avail
;
/*!<currently allocated queue elements */
size_t
step
;
/*!<step size in which new elements are allocated */
...
...
src/kdtreelib/kdtree_spherical.cc
View file @
b2d9b24e
...
...
@@ -11,45 +11,30 @@
general utility functions
********************************************************************* */
inline
kdata_t
kd_sph_dist_sq
(
kdata_t
*
x
,
kdata_t
*
y
)
{
kdata_t
ds
;
/*kdata_t arg;*/
if
(
!
x
||
!
y
)
return
-
1
;
ds
=
acos
(
sin
(
x
[
1
])
*
sin
(
y
[
1
])
+
cos
(
x
[
1
])
*
cos
(
y
[
1
])
*
cos
(
x
[
0
]
-
y
[
0
]));
/* arg = sqrt(kd_sqr(sin((x[1] - y[1])/2)) + cos(x[1]) * cos(y[1]) *
kd_sqr(sin((x[0] - y[0])/2)));
ds = 2 * asin(arg);
*/
return
kd_sqr
(
ds
);
inline
kdata_t
kd_sph_dist
(
kdata_t
*
x
,
kdata_t
*
y
)
{
if
(
!
x
||
!
y
)
return
-
1
;
return
acos
(
sin
(
x
[
1
])
*
sin
(
y
[
1
])
+
cos
(
x
[
1
])
*
cos
(
y
[
1
])
*
cos
(
x
[
0
]
-
y
[
0
]));
}
inline
kdata_t
kd_sph_dist
(
kdata_t
*
x
,
kdata_t
*
y
)
inline
kdata_t
kd_sph_dist
_sq
(
kdata_t
*
x
,
kdata_t
*
y
)
{
kdata_t
ds
;
if
(
!
x
||
!
y
)
return
-
1
;
ds
=
acos
(
sin
(
x
[
1
])
*
sin
(
y
[
1
])
+
cos
(
x
[
1
])
*
cos
(
y
[
1
])
*
cos
(
x
[
0
]
-
y
[
0
]));
return
ds
;
if
(
!
x
||
!
y
)
return
-
1
;
/* arg = sqrt(kd_sqr(sin((x[1] - y[1])/2)) + cos(x[1]) * cos(y[1]) *
kd_sqr(sin((x[0] - y[0])/2)));
ds = 2 * asin(arg);
*/
return
kd_sqr
(
kd_sph_dist
(
x
,
y
));
}
kdata_t
kd_sph_bearing
(
kdata_t
*
p1
,
kdata_t
*
p2
)
{
kdata_t
x
,
y
;
x
=
cos
(
p1
[
1
])
*
sin
(
p2
[
1
])
-
sin
(
p1
[
1
])
*
cos
(
p2
[
1
])
*
cos
(
p2
[
0
]
-
p1
[
0
]);
y
=
sin
(
p2
[
0
]
-
p1
[
0
])
*
cos
(
p2
[
1
]);
return
atan2
(
y
,
x
);
kdata_t
kd_sph_bearing
(
kdata_t
*
p1
,
kdata_t
*
p2
)
{
kdata_t
x
=
cos
(
p1
[
1
])
*
sin
(
p2
[
1
])
-
sin
(
p1
[
1
])
*
cos
(
p2
[
1
])
*
cos
(
p2
[
0
]
-
p1
[
0
]);
kdata_t
y
=
sin
(
p2
[
0
]
-
p1
[
0
])
*
cos
(
p2
[
1
]);
return
atan2
(
y
,
x
);
}
...
...
@@ -64,33 +49,31 @@ kd_sph_bearing(kdata_t *p1, kdata_t *p2)
*/
kdata_t
kd_sph_xtd
(
kdata_t
*
p1
,
kdata_t
*
p2
,
kdata_t
*
p3
)
{
kdata_t
d13
,
theta13
,
theta12
;
d13
=
kd_sph_dist
(
p1
,
p3
);
theta13
=
kd_sph_bearing
(
p1
,
p3
);
theta12
=
kd_sph_bearing
(
p1
,
p2
);
return
asin
(
sin
(
d13
)
*
sin
(
theta13
-
theta12
));
{
kdata_t
d13
=
kd_sph_dist
(
p1
,
p3
);
kdata_t
theta13
=
kd_sph_bearing
(
p1
,
p3
);
kdata_t
theta12
=
kd_sph_bearing
(
p1
,
p2
);
return
asin
(
sin
(
d13
)
*
sin
(
theta13
-
theta12
));
}
kdata_t
kd_sph_orth_dist
(
kdata_t
*
p1
,
kdata_t
*
p2
,
int
split
)
{
kdata_t
ra2
,
dec2
;
kdata_t
ra2
,
dec2
;
kdata_t
dx
;
if
(
split
==
1
)
{
ra2
=
p1
[
0
];
dec2
=
p2
[
1
];
}
else
{
ra2
=
p2
[
0
];
dec2
=
p1
[
1
];
if
(
split
==
1
)
{
ra2
=
p1
[
0
];
dec2
=
p2
[
1
];
}
dx
=
acos
(
sin
(
p1
[
1
])
*
sin
(
dec2
)
+
cos
(
p1
[
1
])
*
cos
(
dec2
)
*
cos
(
p1
[
0
]
-
ra2
));
return
dx
;
else
{
ra2
=
p2
[
0
];
dec2
=
p1
[
1
];
}
return
acos
(
sin
(
p1
[
1
])
*
sin
(
dec2
)
+
cos
(
p1
[
1
])
*
cos
(
dec2
)
*
cos
(
p1
[
0
]
-
ra2
));
}
/* end utility functions */
...
...
@@ -108,13 +91,6 @@ kd_sph_orth_dist(kdata_t *p1, kdata_t *p2, int split)
*
* \param nPoints the length of the points array.
*
* \param constr a pointer to a void *constructor() function to include
* data container in tree; optional, can be NULL
*
* \param destr a pointer to a void destructor() function to free()
* data container in the tree; optional, can be NULL, but should be
* given if the constr argument is non-NULL.
*
* \param min a vector with the minimum positions of the corners of the
* hyperrectangle containing the data.
*
...
...
@@ -133,8 +109,7 @@ kd_sph_buildTree(struct kd_point *points, size_t nPoints,
{
struct
kd_thread_data
my_data
;
kd_initArg
(
&
my_data
,
points
,
nPoints
,
min
,
max
,
0
,
max_threads
,
2
);
struct
kdNode
*
tree
=
(
kdNode
*
)
kd_doBuildTree
(
&
my_data
);
return
tree
;
return
(
kdNode
*
)
kd_doBuildTree
(
&
my_data
);
}
...
...
@@ -289,8 +264,7 @@ kd_sph_ortRangeSearch(struct kdNode *node, kdata_t *min, kdata_t *max)
}
/* This is the orthogonal range search. Returns 1 if okay, 0 in case
of problems. */
/* This is the orthogonal range search. Returns 1 if okay, 0 in case of problems. */
int
kd_sph_doOrtRangeSearch
(
struct
kdNode
*
node
,
kdata_t
*
min
,
kdata_t
*
max
,
struct
pqueue
*
res
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment