00001
#include <volume_io/internal_volume_io.h>
00002
#include <bicpl/deform.h>
00003
#include <limits.h>
00004
00005
private void set_deformation_model(
00006
deformation_model_struct *model,
00007
int up_to_n_points,
00008 Real model_weight,
00009 Deformation_model_types model_type,
00010
object_struct *model_object,
00011 Real min_curvature_offset,
00012 Real max_curvature_offset );
00013
00014 public void initialize_deformation_model(
00015
deformation_model_struct *model )
00016 {
00017 model->
n_models = 0;
00018
00019
set_deformation_model( model, -1, 0.5,
FLAT_MODEL,
00020 (
object_struct *) NULL, -0.3, 0.3 );
00021
00022 model->
position_constrained =
FALSE;
00023 }
00024
00025 private void delete_model_points(
00026
deform_model_struct *model )
00027 {
00028
if( model->
n_model_points > 0 )
00029 {
00030 FREE( model->
model_centroids );
00031 FREE( model->
model_normals );
00032 FREE( model->
model_points );
00033 model->
n_model_points = 0;
00034 }
00035 }
00036
00037 private void delete_deform_model(
00038
deform_model_struct *model )
00039 {
00040
if( model->
model_type ==
GENERAL_MODEL ||
00041 model->
model_type ==
PARAMETRIC_MODEL )
00042 {
00043
delete_model_points( model );
00044 }
00045
00046
if( model->
model_object != (
object_struct *) NULL )
00047 {
00048
delete_object( model->
model_object );
00049 model->
model_object = (
object_struct *) NULL;
00050 }
00051 }
00052
00053 private void set_deformation_model(
00054
deformation_model_struct *model,
00055
int up_to_n_points,
00056 Real model_weight,
00057 Deformation_model_types model_type,
00058
object_struct *model_object,
00059 Real min_curvature_offset,
00060 Real max_curvature_offset )
00061 {
00062
int i, model_index;
00063
00064
if( up_to_n_points <= 0 )
00065 up_to_n_points = INT_MAX;
00066
00067 model_index = 0;
00068
00069
while( model_index < model->
n_models &&
00070 model->
models[model_index].
up_to_n_points < up_to_n_points )
00071 ++model_index;
00072
00073
if( model_index >= model->
n_models ||
00074 model->
models[model_index].
up_to_n_points > up_to_n_points )
00075 {
00076 SET_ARRAY_SIZE( model->
models, model->
n_models, model->
n_models+1,
00077 DEFAULT_CHUNK_SIZE );
00078 ++model->
n_models;
00079
00080
for( i = model->
n_models-1; i >= model_index + 1; --i )
00081 model->
models[i] = model->
models[i-1];
00082 }
00083
else
00084
delete_deform_model( &model->
models[model_index] );
00085
00086 model->
models[model_index].
up_to_n_points = up_to_n_points;
00087 model->
models[model_index].
model_weight = model_weight;
00088 model->
models[model_index].
model_type = model_type;
00089
00090
if( model_type ==
GENERAL_MODEL )
00091 model->
models[model_index].
model_object = model_object;
00092
else
00093 model->
models[model_index].
model_object = (
object_struct *) NULL;
00094
00095 model->
models[model_index].
n_model_points = 0;
00096 model->
models[model_index].
model_centroids = (Point *) NULL;
00097 model->
models[model_index].
model_normals = (Vector *) NULL;
00098 model->
models[model_index].
model_points = (Point *) NULL;
00099
00100 model->
models[model_index].
min_curvature_offset = min_curvature_offset;
00101 model->
models[model_index].
max_curvature_offset = max_curvature_offset;
00102 }
00103
00104 private void print_deform_model(
00105
deform_model_struct *model )
00106 {
00107 STRING model_object_name;
00108 STRING type_name;
00109
00110
switch( model->
model_type )
00111 {
00112
case FLAT_MODEL: type_name =
"flat";
break;
00113
case AVERAGE_MODEL: type_name =
"average";
break;
00114
case PARAMETRIC_MODEL: type_name =
"parametric";
break;
00115
case GENERAL_MODEL: type_name =
"general";
break;
00116
default: type_name =
"error";
break;
00117 }
00118
00119
if( model->
up_to_n_points == INT_MAX )
00120 print(
"All remaining points " );
00121
else
00122 print(
"Up to %7d points ", model->
up_to_n_points );
00123
00124 print(
"%s Wt: %g ", type_name, model->
model_weight );
00125
00126
if( model->
min_curvature_offset <= model->
max_curvature_offset )
00127 {
00128 print(
" Curv: %g %g ",
00129 model->
min_curvature_offset, model->
max_curvature_offset );
00130 }
00131
00132
if( model->
model_object != (
object_struct *) NULL )
00133 {
00134 model_object_name =
get_object_name( model->
model_object );
00135 print(
"%s ", model_object_name );
00136 delete_string( model_object_name );
00137 }
00138
00139
if( model->
n_model_points > 0 )
00140 {
00141 print(
"# model points: %d", model->
n_model_points );
00142 }
00143
00144 print(
"\n" );
00145 }
00146
00147 public void print_deformation_model(
00148
deformation_model_struct *deformation_model )
00149 {
00150
int i;
00151
00152 for_less( i, 0, deformation_model->
n_models )
00153 {
00154 print(
"Model [%d]: ", i );
00155
print_deform_model( &deformation_model->
models[i] );
00156 }
00157
00158
if( deformation_model->
position_constrained )
00159 {
00160 print(
"Position constrained.\n" );
00161 }
00162 }
00163
00164 public Status
add_deformation_model(
00165
deformation_model_struct *deformation_model,
00166
int up_to_n_points,
00167 Real model_weight,
00168
char model_filename[],
00169 Real min_curvature_offset,
00170 Real max_curvature_offset )
00171 {
00172 Status status;
00173
int n_objects;
00174
Deformation_model_types model_type;
00175
object_struct *model_object, **object_list;
00176 File_formats format;
00177
00178 status = OK;
00179
00180 model_object = (
object_struct *) NULL;
00181
00182
if( equal_strings( model_filename,
"flat" ) )
00183 {
00184 model_type =
FLAT_MODEL;
00185 }
00186
else if( equal_strings( model_filename,
"avg" ) )
00187 {
00188 model_type =
AVERAGE_MODEL;
00189 }
00190
else if( equal_strings( model_filename,
"parametric" ) )
00191 {
00192 model_type =
PARAMETRIC_MODEL;
00193 }
00194
else
00195 {
00196 model_type =
GENERAL_MODEL;
00197
00198 status =
input_graphics_file( model_filename, &format,
00199 &n_objects, &object_list );
00200
00201
if( status == OK && n_objects == 0 )
00202 {
00203 print_error(
"File %s has no model object.\n", model_filename );
00204 status = ERROR;
00205 }
00206
else
00207 {
00208 model_object = object_list[0];
00209 }
00210 }
00211
00212
if( status == OK )
00213 {
00214
set_deformation_model( deformation_model, up_to_n_points, model_weight,
00215 model_type, model_object,
00216 min_curvature_offset, max_curvature_offset );
00217 }
00218
00219
return( status );
00220 }
00221
00222 public void delete_deformation_model(
00223
deformation_model_struct *model )
00224 {
00225
int i;
00226
00227 for_less( i, 0, model->
n_models )
00228
delete_deform_model( &model->
models[i] );
00229
00230 FREE( model->
models );
00231 model->
n_models = 0;
00232
00233
if( model->
position_constrained )
00234 FREE( model->
original_positions );
00235 }
00236
00237 public Status
input_original_positions(
00238
deformation_model_struct *deform_model,
00239
char position_filename[],
00240 Real max_position_offset,
00241
int n_deforming_points )
00242 {
00243 Status status, input_status;
00244
int i, n_objects, n_points;
00245
object_struct **object_list;
00246 File_formats format;
00247 Point *points;
00248
lines_struct *lines;
00249
polygons_struct *polygons;
00250
00251
if( deform_model->
position_constrained &&
00252 deform_model->
original_positions != (Point *) NULL )
00253 FREE( deform_model->
original_positions );
00254
00255
if( equal_strings( position_filename,
"none" ) )
00256 {
00257 deform_model->
position_constrained =
FALSE;
00258 }
00259
00260 status =
input_graphics_file( position_filename, &format,
00261 &n_objects, &object_list );
00262
00263 input_status = status;
00264
00265
if( status == OK && n_objects >= 1 && object_list[0]->
object_type ==
LINES )
00266 {
00267 lines =
get_lines_ptr( object_list[0] );
00268 n_points = lines->
n_points;
00269 points = lines->
points;
00270 }
00271
else if( status == OK && n_objects >= 1 &&
00272 object_list[0]->object_type ==
POLYGONS )
00273 {
00274 polygons =
get_polygons_ptr( object_list[0] );
00275 n_points = polygons->
n_points;
00276 points = polygons->
points;
00277 }
00278
else
00279 status = ERROR;
00280
00281
if( n_points != n_deforming_points )
00282 {
00283 print_error(
"Incorrect # of points in original positions file.\n" );
00284 status = ERROR;
00285 }
00286
00287
if( status == OK )
00288 {
00289 ALLOC( deform_model->
original_positions, n_points );
00290 for_less( i, 0, n_points )
00291 deform_model->
original_positions[i] = points[i];
00292 deform_model->
position_constrained =
TRUE;
00293 deform_model->
max_position_offset = max_position_offset;
00294 }
00295
else
00296 deform_model->
position_constrained =
FALSE;
00297
00298
if( input_status == OK )
00299
delete_object_list( n_objects, object_list );
00300
00301
return( status );
00302 }
00303
00304 private void compute_line_model_info(
00305
lines_struct *lines,
00306 Point centroids[],
00307 Vector normals[] )
00308 {
00309
int size, axis, a1, a2, start_index, end_index, vertex_index;
00310
int point_index, neighbours[2], i;
00311 Vector dir_to_next;
00312 BOOLEAN closed;
00313
00314 axis =
find_axial_plane( lines );
00315 a1 = (axis + 1) % 3;
00316 a2 = (axis + 2) % 3;
00317
00318 i = 0;
00319 size =
GET_OBJECT_SIZE( *lines, i );
00320
00321 closed = (size == lines->
n_points+1);
00322
00323
if( closed )
00324 {
00325 start_index = 0;
00326 end_index = lines->
n_points-1;
00327 }
00328
else
00329 {
00330 start_index = 1;
00331 end_index = lines->
n_points-2;
00332 }
00333
00334 for_inclusive( vertex_index, start_index, end_index )
00335 {
00336
get_neighbours_of_line_vertex( lines, vertex_index, neighbours );
00337
00338 point_index = lines->
indices[vertex_index];
00339
00340 INTERPOLATE_POINTS( centroids[point_index],
00341 lines->
points[neighbours[0]],
00342 lines->
points[neighbours[1]], 0.5 );
00343
00344 SUB_POINTS( dir_to_next, lines->
points[neighbours[1]],
00345 lines->
points[neighbours[0]] );
00346
00347 Point_coord(normals[point_index],axis) = Point_coord(dir_to_next,axis);
00348 Point_coord(normals[point_index],a1) = Point_coord(dir_to_next,a2);
00349 Point_coord(normals[point_index],a2) = -Point_coord(dir_to_next,a1);
00350 NORMALIZE_VECTOR( normals[point_index], normals[point_index] );
00351 }
00352 }
00353
00354 private void compute_polygons_model_info(
00355
polygons_struct *polygons,
00356 Point centroids[],
00357 Vector normals[] )
00358 {
00359 Smallest_int *points_done;
00360
int p, size, poly, vertex_index, point_index;
00361 Real base_length, curvature;
00362
00363 ALLOC( points_done, polygons->
n_points );
00364
00365
check_polygons_neighbours_computed( polygons );
00366
00367 for_less( p, 0, polygons->
n_points )
00368 points_done[p] =
FALSE;
00369
00370 for_less( poly, 0, polygons->
n_items )
00371 {
00372 size =
GET_OBJECT_SIZE( *polygons, poly );
00373
00374 for_less( vertex_index, 0, size )
00375 {
00376 point_index = polygons->
indices[
00377
POINT_INDEX(polygons->
end_indices,poly,vertex_index)];
00378
00379
if( !points_done[point_index] )
00380 {
00381 points_done[point_index] =
TRUE;
00382
00383
compute_polygon_point_centroid( polygons, poly,
00384 vertex_index, point_index,
00385 ¢roids[point_index],
00386 &normals[point_index], &base_length, &curvature );
00387 }
00388 }
00389 }
00390
00391 FREE( points_done );
00392 }
00393
00394 private BOOLEAN
check_correct_general_polygons(
00395
polygons_struct *polygons,
00396
deform_model_struct *model )
00397 {
00398
int i, n_up, n_model_up, n_polygon_points;
00399 BOOLEAN sphere_topology, model_sphere_topology;
00400 BOOLEAN tetra_topology, model_tetra_topology;
00401
polygons_struct *model_polygons, *resized_model_polygons;
00402
polygons_struct resized_polygons, half_polygons;
00403
00404
if( model->
model_object == (
object_struct *) NULL )
00405 {
00406 print_error(
"No model object present.\n" );
00407
return(
FALSE );
00408 }
00409
00410
if( model->
model_object->
object_type !=
POLYGONS )
00411 {
00412 print_error(
"Model object is not polygons type.\n" );
00413
return(
FALSE );
00414 }
00415
00416 model_polygons =
get_polygons_ptr( model->
model_object );
00417
00418 sphere_topology =
get_tessellation_of_polygons_sphere( polygons, &n_up);
00419 model_sphere_topology =
get_tessellation_of_polygons_sphere(
00420 model_polygons, &n_model_up);
00421
00422
if( model_sphere_topology != sphere_topology )
00423 {
00424 print_error(
00425
"Model and deforming polygons are not both sphere topology.\n" );
00426
return(
FALSE );
00427 }
00428
00429
if( !sphere_topology )
00430 {
00431 tetra_topology =
is_this_tetrahedral_topology( polygons );
00432 model_tetra_topology =
is_this_tetrahedral_topology( model_polygons );
00433
00434
if( tetra_topology != model_tetra_topology )
00435 {
00436 print_error(
00437
"Model and deforming polygons are not both tetra topology.\n");
00438
return(
FALSE );
00439 }
00440 }
00441
else
00442 tetra_topology =
FALSE;
00443
00444
if( model_polygons->
n_points != polygons->
n_points && !tetra_topology )
00445 {
00446 print_error(
"Can only subsample tetrahedral topology.\n" );
00447
return(
FALSE );
00448 }
00449
00450 n_polygon_points = MIN( polygons->
n_points, model->
up_to_n_points );
00451
00452
if( model->
n_model_points != n_polygon_points )
00453
delete_model_points( model );
00454
00455
if( model->
n_model_points == 0 )
00456 {
00457
if( model_polygons->
n_points == n_polygon_points )
00458 resized_model_polygons = model_polygons;
00459
else
00460 {
00461 resized_polygons = *model_polygons;
00462
do
00463 {
00464
if( sphere_topology )
00465 {
00466
half_sample_sphere_tessellation( &resized_polygons,
00467 &half_polygons );
00468 print_error(
"Subdivided sphere tessellation: %d\n",
00469 half_polygons.
n_points );
00470 }
00471
else
00472 {
00473
half_sample_tetrahedral_tessellation(
00474 &resized_polygons,
00475 &half_polygons );
00476 print_error(
"Subdivided tetrahedal tessellation: %d\n",
00477 half_polygons.
n_points );
00478 }
00479
00480
if( resized_polygons.
n_points < n_polygon_points )
00481
delete_polygons( &resized_polygons );
00482
00483 resized_polygons = half_polygons;
00484 }
00485
while( resized_polygons.
n_points > n_polygon_points );
00486
00487
if( resized_polygons.
n_points != n_polygon_points )
00488 {
00489 print_error(
"Cannot subsample model polygons.\n" );
00490
delete_polygons( &resized_polygons );
00491
return(
FALSE );
00492 }
00493
00494 resized_model_polygons = &resized_polygons;
00495 }
00496
00497 model->
n_model_points = n_polygon_points;
00498 ALLOC( model->
model_centroids, n_polygon_points );
00499 ALLOC( model->
model_normals, n_polygon_points );
00500 ALLOC( model->
model_points, n_polygon_points );
00501
00502 for_less( i, 0, n_polygon_points )
00503 model->
model_points[i] = resized_model_polygons->
points[i];
00504
00505
compute_polygons_model_info( resized_model_polygons,
00506 model->
model_centroids,
00507 model->
model_normals );
00508
00509
if( resized_model_polygons != model_polygons )
00510
delete_polygons( resized_model_polygons );
00511 }
00512
00513
return(
TRUE );
00514 }
00515
00516 private BOOLEAN
check_correct_parametric_polygons(
00517
polygons_struct *polygons,
00518
deform_model_struct *model )
00519 {
00520
int n_up, n_model_up, n_polygon_points, n_items;
00521 Point centre;
00522 BOOLEAN model_sphere_topology, sphere_topology, correct;
00523
polygons_struct *model_polygons;
00524
00525 n_polygon_points = MIN( model->
up_to_n_points, polygons->
n_points );
00526
00527 sphere_topology =
get_tessellation_of_polygons_sphere( polygons, &n_up);
00528
00529
if( model->
model_object != (
object_struct *) NULL )
00530 {
00531
if( model->
model_object->
object_type !=
POLYGONS )
00532
delete_deform_model( model );
00533
00534 model_polygons =
get_polygons_ptr( model->
model_object );
00535
00536 model_sphere_topology =
get_tessellation_of_polygons_sphere(
00537 model_polygons, &n_model_up);
00538
00539
if( sphere_topology != model_sphere_topology ||
00540 model_polygons->
n_points != n_polygon_points )
00541 {
00542
delete_deform_model( model );
00543 }
00544 }
00545
00546
if( model->
model_object == (
object_struct *) NULL )
00547 {
00548 model->
model_object =
create_object(
POLYGONS );
00549 model_polygons =
get_polygons_ptr( model->
model_object );
00550
00551 fill_Point( centre, 0.0, 0.0, 0.0 );
00552
if( sphere_topology )
00553 {
00554 n_up =
get_tessellation_with_n_points( n_polygon_points );
00555 print(
"Creating parametric sphere: %d\n", n_up );
00556
create_polygons_sphere( ¢re, 1.0, 1.0, 1.0, n_up, 2 * n_up,
00557
FALSE, model_polygons );
00558 }
00559
else
00560 {
00561 n_items =
get_tetra_tessellation_with_n_points( n_polygon_points );
00562 print(
"Creating parametric tetrahedral sphere: %d\n", n_items );
00563
create_tetrahedral_sphere( ¢re, 1.0, 1.0, 1.0,
00564 n_items, model_polygons );
00565 }
00566 }
00567
00568 correct =
check_correct_general_polygons( polygons, model );
00569
00570
return( correct );
00571 }
00572
00573 private BOOLEAN
check_correct_subsampled_polygons(
00574
polygons_struct *polygons,
00575
deform_model_struct *model )
00576 {
00577
int n_up, n_model_up, n_polygon_points, n_items;
00578 Point centre;
00579 BOOLEAN model_sphere_topology, sphere_topology;
00580
polygons_struct *model_polygons;
00581
00582 sphere_topology =
get_tessellation_of_polygons_sphere( polygons, &n_up);
00583
00584
if( model->
model_object != (
object_struct *) NULL )
00585 {
00586
if( model->
model_object->
object_type !=
POLYGONS )
00587
delete_deform_model( model );
00588
00589 model_polygons =
get_polygons_ptr( model->
model_object );
00590
00591 model_sphere_topology =
get_tessellation_of_polygons_sphere(
00592 model_polygons, &n_model_up);
00593
00594
if( sphere_topology != model_sphere_topology ||
00595 (sphere_topology && n_model_up != n_up) )
00596 {
00597
delete_deform_model( model );
00598 }
00599 }
00600
00601
if( model->
model_object == (
object_struct *) NULL )
00602 {
00603 n_polygon_points = MIN( model->
up_to_n_points, polygons->
n_points );
00604
00605 model->
model_object =
create_object(
POLYGONS );
00606 model_polygons =
get_polygons_ptr( model->
model_object );
00607
00608 fill_Point( centre, 0.0, 0.0, 0.0 );
00609
if( sphere_topology )
00610 {
00611 n_up =
get_tessellation_with_n_points( n_polygon_points );
00612 print(
"Creating subsampled sphere: %d\n", n_up );
00613
create_polygons_sphere( ¢re, 1.0, 1.0, 1.0, n_up, 2 * n_up,
00614
FALSE, model_polygons );
00615 }
00616
else
00617 {
00618 n_items =
get_tetra_tessellation_with_n_points( n_polygon_points );
00619 print(
"Creating subsampled tetrahedral sphere: %d\n", n_items );
00620
create_tetrahedral_sphere( ¢re, 1.0, 1.0, 1.0,
00621 n_items, model_polygons );
00622 }
00623 }
00624
00625
return(
TRUE );
00626 }
00627
00628 private BOOLEAN
check_correct_model_polygons(
00629
polygons_struct *polygons,
00630
deform_model_struct *model )
00631 {
00632 BOOLEAN correct;
00633
00634
if( model->
model_type ==
PARAMETRIC_MODEL )
00635 correct =
check_correct_parametric_polygons( polygons, model );
00636
else if( model->
model_type ==
GENERAL_MODEL )
00637 correct =
check_correct_general_polygons( polygons, model );
00638
else if( model->
up_to_n_points < polygons->
n_points )
00639 correct =
check_correct_subsampled_polygons( polygons, model );
00640
else
00641 correct =
TRUE;
00642
00643
return( correct );
00644 }
00645
00646 public BOOLEAN
check_correct_deformation_polygons(
00647
polygons_struct *polygons,
00648
deformation_model_struct *model )
00649 {
00650
int model_index;
00651 BOOLEAN model_correct;
00652
00653 model_index = 0;
00654
00655 model_correct =
FALSE;
00656
00657
while( model_index < model->
n_models )
00658 {
00659
if( !
check_correct_model_polygons( polygons,
00660 &model->
models[model_index] ) )
00661 {
00662 model_correct =
FALSE;
00663
break;
00664 }
00665
00666 model_correct =
TRUE;
00667
00668
if( model->
models[model_index].
up_to_n_points >= polygons->
n_points )
00669
break;
00670
00671 ++model_index;
00672 }
00673
00674
return( model_correct );
00675 }
00676
00677 private BOOLEAN
check_correct_general_lines(
00678
lines_struct *lines,
00679
deform_model_struct *model )
00680 {
00681
int i;
00682
lines_struct *model_lines;
00683
00684
if( model->
model_object == (
object_struct *) NULL )
00685 {
00686 print_error(
"No model object present.\n" );
00687
return(
FALSE );
00688 }
00689
00690
if( model->
model_object->
object_type !=
LINES )
00691 {
00692 print_error(
"Model object is not lines type.\n" );
00693
return(
FALSE );
00694 }
00695
00696 model_lines =
get_lines_ptr( model->
model_object );
00697
00698
if( model_lines->
n_points != lines->
n_points )
00699 {
00700 print_error(
00701
"Model lines must have same number of points as deforming lines.\n" );
00702
return(
FALSE );
00703 }
00704
00705
if( model->
n_model_points != lines->
n_points )
00706
delete_model_points( model );
00707
00708
if( model->
n_model_points == 0 )
00709 {
00710 model->
n_model_points = lines->
n_points;
00711 ALLOC( model->
model_centroids, lines->
n_points );
00712 ALLOC( model->
model_normals, lines->
n_points );
00713 ALLOC( model->
model_points, lines->
n_points );
00714
00715 for_less( i, 0, lines->
n_points )
00716 model->
model_points[i] = model_lines->
points[i];
00717
00718
compute_line_model_info( model_lines,
00719 model->
model_centroids,
00720 model->
model_normals );
00721 }
00722
00723
return(
TRUE );
00724 }
00725
00726 private BOOLEAN
check_correct_parametric_lines(
00727
lines_struct *lines,
00728
deform_model_struct *model )
00729 {
00730 Point centre;
00731 BOOLEAN correct;
00732
lines_struct *model_lines;
00733
00734
if( model->
model_object != (
object_struct *) NULL )
00735 {
00736
if( model->
model_object->
object_type !=
LINES ||
00737 model->
n_model_points != lines->
n_points )
00738 {
00739
delete_deform_model( model );
00740 }
00741 }
00742
00743
if( model->
model_object == (
object_struct *) NULL )
00744 {
00745 model->
model_object =
create_object(
LINES );
00746 model_lines =
get_lines_ptr( model->
model_object );
00747
00748 fill_Point( centre, 0.0, 0.0, 0.0 );
00749
00750
create_line_circle( ¢re, Z, 1.0, 1.0, lines->
n_points, model_lines);
00751 }
00752
00753 correct =
check_correct_general_lines( lines, model );
00754
00755
return( correct );
00756 }
00757
00758 private BOOLEAN
check_correct_model_lines(
00759
lines_struct *lines,
00760
deform_model_struct *model )
00761 {
00762 BOOLEAN correct;
00763
00764
if( model->
model_type ==
PARAMETRIC_MODEL )
00765 correct =
check_correct_parametric_lines( lines, model );
00766
else if( model->
model_type ==
GENERAL_MODEL )
00767 correct =
check_correct_general_lines( lines, model );
00768
else
00769 correct =
TRUE;
00770
00771
return( correct );
00772 }
00773
00774 public BOOLEAN
check_correct_deformation_lines(
00775
lines_struct *lines,
00776
deformation_model_struct *model )
00777 {
00778
int model_index;
00779 BOOLEAN model_correct;
00780
00781 model_index = 0;
00782
00783 model_correct =
FALSE;
00784
00785
while( model_index < model->
n_models )
00786 {
00787
if( !
check_correct_model_lines( lines,
00788 &model->
models[model_index] ) )
00789 {
00790 model_correct =
FALSE;
00791
break;
00792 }
00793
00794 model_correct =
TRUE;
00795
00796
if( model->
models[model_index].
up_to_n_points >= lines->
n_points )
00797
break;
00798
00799 ++model_index;
00800 }
00801
00802
return( model_correct );
00803 }
00804
00805 public deform_model_struct *
find_relevent_model(
00806
deformation_model_struct *model,
00807
int point_index )
00808 {
00809
int model_index;
00810
00811 model_index = 0;
00812
while( model_index < model->
n_models &&
00813 point_index >= model->
models[model_index].
up_to_n_points )
00814 {
00815 ++model_index;
00816 }
00817
00818
if( model_index >= model->
n_models )
00819 {
00820 HANDLE_INTERNAL_ERROR(
"get_model_point" );
00821 }
00822
00823
return( &model->
models[model_index] );
00824 }