/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        R E C H E R C H E   T R I D I M E N S I O N N E L L E   D E   P O I N T S   V O I S I N S   D A N S   U N   A L B U M  :   */
/*                                                                                                                                   */
/*                                                                                                                                   */
/*        Author of '$xrv/PointsVoisins_3D.01$K' :                                                                                   */
/*                                                                                                                                   */
/*                    Jean-Francois COLONNA (LACTAMME, 20150809093608).                                                              */
/*                                                                                                                                   */
/*************************************************************************************************************************************/

/*===================================================================================================================================*/
/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        I N T E R F A C E   ' listG '  :                                                                                           */
/*                                                                                                                                   */
/*                                                                                                                                   */
/*        :Debut_listG:                                                                                                              */
/*        :Fin_listG:                                                                                                                */
/*                                                                                                                                   */
/*************************************************************************************************************************************/

/*===================================================================================================================================*/
/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        D I R E C T I V E S   S P E C I F I Q U E S   D E   C O M P I L A T I O N  :                                               */
/*                                                                                                                                   */
/*************************************************************************************************************************************/

/*===================================================================================================================================*/
/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        F I C H I E R S   D ' I N C L U D E S  :                                                                                   */
/*                                                                                                                                   */
/*************************************************************************************************************************************/
#include  INCLUDES_BASE
#include  image_image_IMAGESF_EXT

/*===================================================================================================================================*/
/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        V A L E U R S   I M P L I C I T E S   D E S   P A R A M E T R E S  :                                                       */
/*                                                                                                                                   */
/*************************************************************************************************************************************/
#include  xci/album.01.I"

#define   COMPATIBILITE_20150813                                                                                                        \
                    FAUX                                                                                                                \
                                        /* Permet de faire des calculs compatibles a ceux faits anterieurement au 20150813172627...  */

#define   UTILISER_DES_SPHERES_PLUTOT_QUE_DES_CUBES                                                                                     \
                    VRAI                                                                                                                \
                                        /* Doit-on utiliser des cubes "concentriques" ('FAUX') ou bien des spheres concentriques     */ \
                                        /* ('VRAI'). Ceci a ete introduit le 20150813175902...                                       */

#define   NIVEAU_DES_POINTS                                                                                                             \
                    BLANC                                                                                                               \
                                        /* Niveau des points a etudier...                                                            */

#define   NOMBRE_DE_VOISINS_CHERCHES                                                                                                    \
                    SIX                                                                                                                 \
                                        /* Nombre de voisins recherches.                                                             */
#define   NOMBRE_MAXIMAL_DE_POINTS_A_TESTER                                                                                             \
                    MILLE                                                                                                               \
                                        /* Nombre maximal de points a tester autour de chaque point de 'niveau_des_points'.          */
#define   DISTANCE_MINIMALE_ENTRE_DEUX_POINTS                                                                                           \
                    FZERO
#define   DISTANCE_MAXIMALE_ENTRE_DEUX_POINTS                                                                                           \
                    F_INFINI
                                        /* Distances extremales entre deux points voisins (le minimum a ete introduit                */
                                        /* 20150812093727).                                                                          */
#define   TRIER_LES_DEUX_POINTS_DANS_UN_COUPLE                                                                                          \
                    VRAI                                                                                                                \
                                        /* Faut-il trier les deux points d'un couple {A,B} de facon a ce que {B,A} apparaissent      */
                                        /* sous la forme {A,B} ('VRAI') ou pas ('FAUX') ?                                            */

/*===================================================================================================================================*/
/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        D E F I N I T I O N   D E S   F I C H I E R S  :                                                                           */
/*                                                                                                                                   */
/*************************************************************************************************************************************/
#include  xrv/ARITHMET.1d.I"
#include  xrv/ARITHMET.21.I"
#include  xrv/champs_5.41.I"

/*===================================================================================================================================*/
/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        M A C R O S   U T I L E S  :                                                                                               */
/*                                                                                                                                   */
/*************************************************************************************************************************************/
#define   AMPLITUDE_XYZ                                                                                                                 \
                    CHOY(PasX,PasY,PasZ)

#define   PREMIER_VOISIN                                                                                                                \
                    INDEX0
#define   LISTE_DES_VOISINS(index)                                                                                                      \
                    IdTb1(liste_des_voisins_du_point_courant                                                                            \
                         ,INDX(index,PREMIER_VOISIN)                                                                                    \
                         ,nombre_de_voisins_cherches                                                                                    \
                          )
#define   COORDONNEES_DES_VOISINS(index,coordonnee)                                                                                     \
                    ASD1(LISTE_DES_VOISINS(index)                                                                                       \
                        ,coordonnee                                                                                                     \
                         )
                                        /* Acces a la liste des voisins (introduit le 20150813130734).                               */

#define   cXA                                                                                                                           \
                    SOUS(ASD1(point_central_courant,x),amplitude_X)
#define   cXB                                                                                                                           \
                    ADD2(ASD1(point_central_courant,x),amplitude_X)
#define   cXC                                                                                                                           \
                    cXB
#define   cXD                                                                                                                           \
                    cXA

#define   cXE                                                                                                                           \
                    cXA
#define   cXF                                                                                                                           \
                    cXB
#define   cXG                                                                                                                           \
                    cXC
#define   cXH                                                                                                                           \
                    cXD

#define   cYA                                                                                                                           \
                    SOUS(ASD1(point_central_courant,y),amplitude_Y)
#define   cYB                                                                                                                           \
                    cYA
#define   cYC                                                                                                                           \
                    ADD2(ASD1(point_central_courant,y),amplitude_Y)
#define   cYD                                                                                                                           \
                    cYC

#define   cYE                                                                                                                           \
                    cYA
#define   cYF                                                                                                                           \
                    cYB
#define   cYG                                                                                                                           \
                    cYC
#define   cYH                                                                                                                           \
                    cYD

#define   cZA                                                                                                                           \
                    SOUS(ASD1(point_central_courant,z),amplitude_Z)
#define   cZB                                                                                                                           \
                    cZA
#define   cZC                                                                                                                           \
                    cZA
#define   cZD                                                                                                                           \
                    cZA

#define   cZE                                                                                                                           \
                    ADD2(ASD1(point_central_courant,z),amplitude_Z)
#define   cZF                                                                                                                           \
                    cZE
#define   cZG                                                                                                                           \
                    cZE
#define   cZH                                                                                                                           \
                    cZE

#define   cX_AD__                                                                                                                       \
                    CHOI(cXA,cXD)
#define   cX_AEHD                                                                                                                       \
                    CHOZ(cXA,cXE,cXH,cXD)
#define   cX_AE__                                                                                                                       \
                    CHOI(cXA,cXE)
#define   cX_BC__                                                                                                                       \
                    CHOI(cXB,cXC)
#define   cX_BFGC                                                                                                                       \
                    CHOZ(cXB,cXF,cXG,cXC)
#define   cX_BF__                                                                                                                       \
                    CHOI(cXB,cXF)
#define   cX_CG__                                                                                                                       \
                    CHOI(cXC,cXG)
#define   cX_DH__                                                                                                                       \
                    CHOI(cXD,cXH)
#define   cX_EH__                                                                                                                       \
                    CHOI(cXE,cXH)
#define   cX_FG__                                                                                                                       \
                    CHOI(cXF,cXG)

#define   cY_ABFE                                                                                                                       \
                    CHOZ(cYA,cYB,cYF,cYE)
#define   cY_AB__                                                                                                                       \
                    CHOI(cYA,cYB)
#define   cY_AE__                                                                                                                       \
                    CHOI(cYA,cYE)
#define   cY_BF__                                                                                                                       \
                    CHOI(cYB,cYF)
#define   cY_CD__                                                                                                                       \
                    CHOI(cYC,cYD)
#define   cY_CG__                                                                                                                       \
                    CHOI(cYC,cYG)
#define   cY_DCGH                                                                                                                       \
                    CHOZ(cYD,cYC,cYG,cYH)
#define   cY_DH__                                                                                                                       \
                    CHOI(cYD,cYH)
#define   cY_EF__                                                                                                                       \
                    CHOI(cYE,cYF)
#define   cY_GH__                                                                                                                       \
                    CHOI(cYG,cYH)

#define   cZ_ABCD                                                                                                                       \
                    CHOZ(cZA,cZB,cZC,cZD)
#define   cZ_AB__                                                                                                                       \
                    CHOI(cZA,cZB)
#define   cZ_AD__                                                                                                                       \
                    CHOI(cZA,cZD)
#define   cZ_BC__                                                                                                                       \
                    CHOI(cZB,cZC)
#define   cZ_DC__                                                                                                                       \
                    CHOI(cZD,cZC)
#define   cZ_EFGH                                                                                                                       \
                    CHOZ(cZE,cZF,cZG,cZH)
#define   cZ_EF__                                                                                                                       \
                    CHOI(cZE,cZF)
#define   cZ_EH__                                                                                                                       \
                    CHOI(cZE,cZH)
#define   cZ_FG__                                                                                                                       \
                    CHOI(cZF,cZG)
#define   cZ_HG__                                                                                                                       \
                    CHOI(cZH,cZG)
                                        /* Definition du cube courant de centre 'point_central_courant' :                            */
                                        /*                                                                                           */
                                        /*                                                                                           */
                                        /*                        H ---------- G                                                     */
                                        /*                                                                                           */
                                        /*                      / .          / |                                                     */
                                        /*                     /  .         /  |                                                     */
                                        /*                    /   .        /   |                                                     */
                                        /*                        .            |                                                     */
                                        /*                  D ---------- C     |                                                     */
                                        /*                                                                                           */
                                        /*                  |     E .....|.... F                                                     */
                                        /*                  |            |                                                           */
                                        /*                  |   .        |   /                                                       */
                                        /*                  |  .         |  /                                                        */
                                        /*                  | .          | /                                                         */
                                        /*                                                                                           */
                                        /*                  A ---------- B                                                           */
                                        /*                                                                                           */

#define   distance_minimale_locale_entre_deux_points                                                                                    \
                    distance_minimale_entre_deux_points
#define   distance_maximale_locale_entre_deux_points                                                                                    \
                    distance_maximale_entre_deux_points
#include  xrv/PointsVoisins_2D.01.I"

#define   PARCOURS_D_UNE_STRUCTURE_LINEAIRE(x1,x2,y1,y2,z1,z2)                                                                          \
                    Bblock                                                                                                              \
                    Test(IL_FAUT(iterer_la_recherche_des_voisins_du_point_central_courant))                                             \
                                        /* Ce test apparemment redondant est la pour des raisons d'optimisation...                   */ \
                         Bblock                                                                                                         \
                         begin_albumQ(DoIn,MIN2(z1,z2),MAX2(z1,z2),PasZ                                                                 \
                                     ,DoIn,MIN2(y1,y2),MAX2(y1,y2),PasY                                                                 \
                                     ,DoIn,MIN2(x1,x2),MAX2(x1,x2),PasX                                                                 \
                                      )                                                                                                 \
                                        /* Parcours d'un sous-ensemble du cube {{x1,x2},{y1,y2},{z1,z2}},                            */ \
                              Bblock                                                                                                    \
                              Test(IL_FAUT(iterer_la_recherche_des_voisins_du_point_central_courant))                                   \
                                        /* Ce test apparemment redondant est la pour des raisons d'optimisation...                   */ \
                                   Bblock                                                                                               \
                                   DEFV(Int,INIT(X_effectif,X));                                                                        \
                                   DEFV(Int,INIT(Y_effectif,Y));                                                                        \
                                   DEFV(Int,INIT(Z_effectif,Z));                                                                        \
                                        /* Introduit le 20150813113406 en prevision d'une possible extension en autorisant en        */ \
                                        /* plus des cubes concentriques, des spheres concentriques qui auraient l'avantage, par      */ \
                                        /* rapport aux cubes, de permettre une recherche isotrope...                                 */ \
                                                                                                                                        \
                                   Test(IL_FAUT(utiliser_des_spheres_plutot_que_des_cubes))                                             \
                                        /* Test introduit le 20150813180227...                                                       */ \
                                        Bblock                                                                                          \
                                        DEFV(Float,INIT(delta_X,FLOT(SOUS(ASD1(point_central_courant,x),X_effectif))));                 \
                                        DEFV(Float,INIT(delta_Y,FLOT(SOUS(ASD1(point_central_courant,y),Y_effectif))));                 \
                                        DEFV(Float,INIT(delta_Z,FLOT(SOUS(ASD1(point_central_courant,z),Z_effectif))));                 \
                                        DEFV(Float,INIT(phi_,FLOT__UNDEF));                                                             \
                                        DEFV(Float,INIT(theta,FLOT__UNDEF));                                                            \
                                                                                                                                        \
                                        EGAL(phi_,Phi_3D(delta_X,delta_Y,delta_Z));                                                     \
                                        EGAL(theta,Theta_3D(delta_X,delta_Y,delta_Z));                                                  \
                                        /* On notera que :                                                                           */ \
                                        /*                                                                                           */ \
                                        /*                  EGAL(rho_,Rho_3D(delta_X,delta_Y,delta_Z));                              */ \
                                        /*                                                                                           */ \
                                        /* serait inutile puisque l'on va forcer 'rayon_des_spheres' juste apres...                  */ \
                                                                                                                                        \
                                        EGAL(X_effectif                                                                                 \
                                            ,ADD2(ASD1(point_central_courant,x)                                                         \
                                                 ,INTE(Xcartesienne_3D(rayon_des_spheres,phi_,theta))                                   \
                                                  )                                                                                     \
                                             );                                                                                         \
                                        EGAL(Y_effectif                                                                                 \
                                            ,ADD2(ASD1(point_central_courant,y)                                                         \
                                                 ,INTE(Ycartesienne_3D(rayon_des_spheres,phi_,theta))                                   \
                                                  )                                                                                     \
                                             );                                                                                         \
                                        EGAL(Z_effectif                                                                                 \
                                            ,ADD2(ASD1(point_central_courant,z)                                                         \
                                                 ,INTE(Zcartesienne_3D(rayon_des_spheres,phi_,theta))                                   \
                                                  )                                                                                     \
                                             );                                                                                         \
                                        /* Ainsi, on ramene les points du cube a la surface de la sphere inscrite. Au passage,       */ \
                                        /* il y a moins de points sur une sphere quantifiee que sur un cube lui-aussi quantifie      */ \
                                        /* et c'est cela qui a necessite la mise en place de 'LISTE_DES_VOISINS(...)'...             */ \
                                        Eblock                                                                                          \
                                   ATes                                                                                                 \
                                        Bblock                                                                                          \
                                        Eblock                                                                                          \
                                   ETes                                                                                                 \
                                                                                                                                        \
                                   Test(I3ET(IFEQ(X_effectif,ASD1(point_central_courant,x))                                             \
                                            ,IFEQ(Y_effectif,ASD1(point_central_courant,y))                                             \
                                            ,IFEQ(Z_effectif,ASD1(point_central_courant,z))                                             \
                                             )                                                                                          \
                                        )                                                                                               \
                                        Bblock                                                                                          \
                                        /* Cas ou l'on est sur le point central qui ne peut donc etre son propre voisin...           */ \
                                        /*                                                                                           */ \
                                        /* On notera que ce test est peut-etre inutile a cause de l'intialisation qui est faite      */ \
                                        /* de {amplitude_X,amplitude_Y,amplitude_Z} et qui est telle que le point {X,Y,Z} ne peut    */ \
                                        /* jamais etre le point central (on commence par le plus petit carre le contenant...).       */ \
                                        /* Malgre tout, il est preferable de le conserver, on ne sait jamais...                      */ \
                                        Eblock                                                                                          \
                                   ATes                                                                                                 \
                                        Bblock                                                                                          \
                                        Test(TEST_DANS_L_ALBUM(X_effectif,Y_effectif,Z_effectif))                                       \
                                             Bblock                                                                                     \
                                             Test(IFEQ(Aload_point(album_d_images,X_effectif,Y_effectif,Z_effectif)                     \
                                                      ,niveau_des_points                                                                \
                                                       )                                                                                \
                                                  )                                                                                     \
                                        /* Le point {X_effectif,Y_effectif,Z_effectif} est un voisin possible, mais il a peut-etre   */ \
                                        /* ete deja rencontre...                                                                     */ \
                                                  Bblock                                                                                \
                                                  DEFV(Logical,INIT(ce_voisin_a_deja_ete_rencontre,FAUX));                              \
                                                                                                                                        \
                                                  Test(IL_NE_FAUT_PAS(compatibilite_20150813))                                          \
                                        /* Test introduit le 20150813172627...                                                       */ \
                                                       Bblock                                                                           \
                                                       DEFV(Int,INIT(index_des_voisins,UNDEF));                                         \
                                                                                                                                        \
                                                       DoIn(index_des_voisins                                                           \
                                                           ,PREMIER_VOISIN                                                              \
                                                           ,LSTX(PREMIER_VOISIN,nombre_de_voisins_trouves)                              \
                                                           ,I                                                                           \
                                                            )                                                                           \
                                                            Bblock                                                                      \
                                                            Test(IFEQ_Rpoints3D(X_effectif                                              \
                                                                               ,Y_effectif                                              \
                                                                               ,Z_effectif                                              \
                                                                               ,COORDONNEES_DES_VOISINS(index_des_voisins,x)            \
                                                                               ,COORDONNEES_DES_VOISINS(index_des_voisins,y)            \
                                                                               ,COORDONNEES_DES_VOISINS(index_des_voisins,z)            \
                                                                                )                                                       \
                                                                 )                                                                      \
                                                                 Bblock                                                                 \
                                                                 EGAL(ce_voisin_a_deja_ete_rencontre,VRAI);                             \
                                        /* Ce voisin a deja ete rencontre dans cette structure...                                    */ \
                                        /*                                                                                           */ \
                                        /* On notera que ce dispositif est utile aussi avec les cubes "concentriques" car, en        */ \
                                        /* effet, les sommets et les aretes sont explorees plusieurs fois puisqu'ils appartiennent   */ \
                                        /* a plusieurs aretes et plusieurs faces...                                                  */ \
                                        /*                                                                                           */ \
                                        /* Le 20150814071404 je note d'ailleurs qu'avant ce dispositif certains points devenaient    */ \
                                        /* des voisins multiples (appartenant donc a des aretes ou des sommets de cube). Cela        */ \
                                        /* faisait donc qu'ils comptaient pour plusieurs voisins (alors donc qu'ils etaient          */ \
                                        /* identiques) et ainsi on n'atteignait pas 'nombre_de_voisins_cherches' avec des voisins    */ \
                                        /* tous differents, ce qui est donc maintenant le cas...                                     */ \
                                                                 Eblock                                                                 \
                                                            ATes                                                                        \
                                                                 Bblock                                                                 \
                                                                 Eblock                                                                 \
                                                            ETes                                                                        \
                                                            Eblock                                                                      \
                                                       EDoI                                                                             \
                                                       Eblock                                                                           \
                                                  ATes                                                                                  \
                                                       Bblock                                                                           \
                                                       Eblock                                                                           \
                                                  ETes                                                                                  \
                                                                                                                                        \
                                                  Test(EST_FAUX(ce_voisin_a_deja_ete_rencontre))                                        \
                                        /* Test introduit le 20150813130734...                                                       */ \
                                                       Bblock                                                                           \
                                        /* Cas ou le point courant est un "bon" voisin du point central courant :                    */ \
                                                       DEFV(Float,INIT(coordonnee_X1                                                    \
                                                                      ,_____cNORMALISE_OX(ASD1(point_central_courant,x))                \
                                                                       )                                                                \
                                                            );                                                                          \
                                                       DEFV(Float,INIT(coordonnee_Y1                                                    \
                                                                      ,_____cNORMALISE_OY(ASD1(point_central_courant,y))                \
                                                                       )                                                                \
                                                            );                                                                          \
                                                       DEFV(Float,INIT(coordonnee_Z1                                                    \
                                                                      ,_____cNORMALISE_OZ(ASD1(point_central_courant,z))                \
                                                                       )                                                                \
                                                            );                                                                          \
                                                       DEFV(Float,INIT(coordonnee_X2,_____cNORMALISE_OX(X_effectif)));                  \
                                                       DEFV(Float,INIT(coordonnee_Y2,_____cNORMALISE_OY(Y_effectif)));                  \
                                                       DEFV(Float,INIT(coordonnee_Z2,_____cNORMALISE_OZ(Z_effectif)));                  \
                                                                                                                                        \
                                                       DEFV(Int,INIT(save_nombre_de_voisins_trouves,nombre_de_voisins_trouves));        \
                                                                                                                                        \
                                                       EDITION_D_UN_POINT_VOISIN;                                                       \
                                        /* Edition d'un nouveau voisin et comptage...                                                */ \
                                                                                                                                        \
                                                       Test(IFET(IL_NE_FAUT_PAS(compatibilite_20150813)                                 \
                                                                ,IFGT(nombre_de_voisins_trouves,save_nombre_de_voisins_trouves)         \
                                                                 )                                                                      \
                                                            )                                                                           \
                                        /* Cas ou un voisin a ete trouve :                                                           */ \
                                                            Bblock                                                                      \
                                                            INITIALISATION_POINT_3D(LISTE_DES_VOISINS(LSTX(PREMIER_VOISIN               \
                                                                                                          ,nombre_de_voisins_trouves    \
                                                                                                           )                            \
                                                                                                      )                                 \
                                                                                   ,X_effectif                                          \
                                                                                   ,Y_effectif                                          \
                                                                                   ,Z_effectif                                          \
                                                                                    );                                                  \
                                        /* Memorisation du nouveau voisin...                                                         */ \
                                                            Eblock                                                                      \
                                                       ATes                                                                             \
                                                            Bblock                                                                      \
                                                            Eblock                                                                      \
                                                       ETes                                                                             \
                                                       Eblock                                                                           \
                                                  ATes                                                                                  \
                                                       Bblock                                                                           \
                                                       Eblock                                                                           \
                                                  ETes                                                                                  \
                                                  Eblock                                                                                \
                                             ATes                                                                                       \
                                                  Bblock                                                                                \
                                                  Eblock                                                                                \
                                             ETes                                                                                       \
                                             Eblock                                                                                     \
                                        ATes                                                                                            \
                                             Bblock                                                                                     \
                                             Eblock                                                                                     \
                                        ETes                                                                                            \
                                        Eblock                                                                                          \
                                   ETes                                                                                                 \
                                                                                                                                        \
                                   INCR(nombre_de_points_testes,I);                                                                     \
                                        /* Comptage des points testes (meme ceux qui sont hors album et ce afin de ne pas creer      */ \
                                        /* d'effets de bord...).                                                                     */ \
                                                                                                                                        \
                                   Test(IFET(IFLT(nombre_de_points_testes,nombre_maximal_de_points_a_tester)                            \
                                            ,IFLT(nombre_de_voisins_trouves,nombre_de_voisins_cherches)                                 \
                                             )                                                                                          \
                                        )                                                                                               \
                                        Bblock                                                                                          \
                                        Eblock                                                                                          \
                                   ATes                                                                                                 \
                                        Bblock                                                                                          \
                                        EGAL(iterer_la_recherche_des_voisins_du_point_central_courant,FAUX);                            \
                                        Eblock                                                                                          \
                                   ETes                                                                                                 \
                                   Eblock                                                                                               \
                              ATes                                                                                                      \
                                   Bblock                                                                                               \
                                   Eblock                                                                                               \
                              ETes                                                                                                      \
                              Eblock                                                                                                    \
                         end_albumQ(EDoI,EDoI,EDoI)                                                                                     \
                         Eblock                                                                                                         \
                    ATes                                                                                                                \
                         Bblock                                                                                                         \
                         Eblock                                                                                                         \
                    ETes                                                                                                                \
                    Eblock                                                                                                              \
                                        /* Procedure de parcours d'une structure lineaire tridimensionnelle.                         */

/*===================================================================================================================================*/
/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        R E C H E R C H E   T R I D I M E N S I O N N E L L E   D E   P O I N T S   V O I S I N S   D A N S   U N   A L B U M  :   */
/*                                                                                                                                   */
/*************************************************************************************************************************************/
BCommande(nombre_d_arguments,arguments)
/*-----------------------------------------------------------------------------------------------------------------------------------*/
     Bblock
     DEFV(Logical,INIT(compatibilite_20150813,COMPATIBILITE_20150813));
                                        /* Permet de faire des calculs compatibles a ceux faits anterieurement au 20150813172627...  */

#include  xrv/ARITHMET.22.I"
#include  xci/valeurs.03.I"

     DEFV(CHAR,INIT(POINTERc(nom_imageA),NOM_PIPE_Local));
                                        /* Nom des images.                                                                           */

     DEFV(CHAR,INIC(POINTERc(nom_postfixe),NOM_UNDEF_VIDE));
                                        /* Nom d'un eventuel postfixe a placer derriere <nom_imageA><numero> (par exemple '$ROUGE'). */
     DEFV(Int,INIT(premiere_image,PREMIERE_IMAGE));
                                        /* Numero de la premiere image,                                                              */
     DEFV(Int,INIT(pas_des_images,PAS_DES_IMAGES));
                                        /* Pas de passage d'un numero d'image a une autre.                                           */
     DEFV(Int,INIT(nombre_de_chiffres,NOMBRE_DE_CHIFFRES));
                                        /* Nombre de chiffres codant le numero des images de la serie...                             */

     DEFV(Logical,INIT(utiliser_des_spheres_plutot_que_des_cubes,UTILISER_DES_SPHERES_PLUTOT_QUE_DES_CUBES));
                                        /* Doit-on utiliser des cubes "concentriques" ('FAUX') ou bien des spheres concentriques     */
                                        /* ('VRAI'). Ceci a ete introduit le 20150813175902...                                       */

     DEFV(genere_p,INIT(niveau_des_points,NIVEAU_DES_POINTS));
                                        /* Niveau des points a etudier...                                                            */

     DEFV(Positive,INIT(nombre_de_voisins_cherches,NOMBRE_DE_VOISINS_CHERCHES));
                                        /* Nombre de voisins recherches.                                                             */
     DEFV(Positive,INIT(nombre_maximal_de_points_a_tester,NOMBRE_MAXIMAL_DE_POINTS_A_TESTER));
                                        /* Nombre maximal de points a tester autour de chaque point de 'niveau_des_points'.          */
     DEFV(Float,INIT(distance_minimale_entre_deux_points,DISTANCE_MINIMALE_ENTRE_DEUX_POINTS));
     DEFV(Float,INIT(distance_maximale_entre_deux_points,DISTANCE_MAXIMALE_ENTRE_DEUX_POINTS));
                                        /* Distances extremales entre deux points voisins (le minimum a ete introduit                */
                                        /* 20150812093727).                                                                          */

     DEFV(Logical,INIT(trier_les_deux_points_dans_un_couple,TRIER_LES_DEUX_POINTS_DANS_UN_COUPLE));
                                        /* Faut-il trier les deux points d'un couple {A,B} de facon a ce que {B,A} apparaissent      */
                                        /* sous la forme {A,B} ('VRAI') ou pas ('FAUX') ?                                            */
     /*..............................................................................................................................*/
     GET_ARGUMENTSi(nombre_d_arguments
                   ,BLOC(GET_ARGUMENT_L("compatibilite_20150813=",compatibilite_20150813);

                         PROCESS_ARGUMENT_I("nombre_elements=""ne=",nombre_d_elements
                                           ,BLOC(VIDE;)
                                           ,BLOC(Bblock
                                                 PRINT_AVERTISSEMENT("'ne=' doit etre defini avant toute entree de fichiers");
                                                 Eblock
                                                 )
                                            );

                         PROCESS_ARGUMENTS_DE_DEFINITION_DES_FICHIERS_01;

                         GET_ARGUMENT_C("imageA=""A=",nom_imageA);
                         GET_ARGUMENT_C("postfixe=",nom_postfixe);
                         GET_ARGUMENT_I("premiere=",premiere_image);
                         GET_ARGUMENT_I("pas=",pas_des_images);
                                        /* ATTENTION, jusqu'au 20150813122542, il y avait ici :                                      */
                                        /*                                                                                           */
                                        /*                  GET_ARGUMENTS2_I("pas=",pas_des_images,pasZ);                            */
                                        /*                                                                                           */
                                        /* mais etant donne que partout, ce sont {PasX,PasY,PasZ} qui sont utilises, mieux vaut      */
                                        /* ne pas modifier 'pasZ' ici...                                                             */
                         GET_ARGUMENT_I("chiffres=",nombre_de_chiffres);

                         GET_ARGUMENT_L("spheres=""sp=",utiliser_des_spheres_plutot_que_des_cubes);
                         GET_ARGUMENT_N("cubes=""cu=",utiliser_des_spheres_plutot_que_des_cubes);
                                        /* Arguments introduits le 20150813175902...                                                 */

                         GET_ARGUMENT_P("niveau=""n=",niveau_des_points);

                         GET_ARGUMENT_I("nombre_voisins=""nv=",nombre_de_voisins_cherches);
                         GET_ARGUMENT_I("nombre_points=""np=",nombre_maximal_de_points_a_tester);
                         GET_ARGUMENT_F("distance_minimale=""dm=",distance_minimale_entre_deux_points);
                         GET_ARGUMENT_F("distance_maximale=""dM=",distance_maximale_entre_deux_points);

                         GET_ARGUMENT_L("trier_couple=""trier=""tc=",trier_les_deux_points_dans_un_couple);
                         )
                    );

     begin_nouveau_block
          Bblock
          BDEFV(album,album_d_images);
                                        /* Definition de l'album d'images a explorer.                                                */
          CALi(dAload_album(album_d_images
                           ,nom_imageA
                           ,nom_postfixe
                           ,premiere_image
                           ,pas_des_images
                           ,nombre_de_chiffres
                           ,FAUX
                           ,UNDEF
                           ,FAUX
                            )
               );

          Test(PAS_D_ERREUR(CODE_ERREUR))
               Bblock
               begin_album
                    Bblock
                    Test(IFEQ(Aload_point(album_d_images,X,Y,Z),niveau_des_points))
                         Bblock
                         DEFV(Logical,INIT(iterer_la_recherche_des_voisins_du_point_central_courant,VRAI));
                                        /* Controle des iterations...                                                                */
                         DEFV(Int,INIT(nombre_de_voisins_trouves,ZERO));
                         DEFV(Int,INIT(nombre_de_points_testes,ZERO));
                                        /* Compteurs divers...                                                                       */
                         DEFV(Int,INIT(amplitude_X,AMPLITUDE_XYZ));
                         DEFV(Int,INIT(amplitude_Y,AMPLITUDE_XYZ));
                         DEFV(Int,INIT(amplitude_Z,AMPLITUDE_XYZ));
                                        /* Pour definir les surfaces des cubes imbriques les uns dans les autres, a la facon d'un    */
                                        /* oignon cubique. On notera au passage que l'on ne commence pas par un cube "nul" car,      */
                                        /* en effet, il ne contiendrait qu'un seul point, le 'point_central_courant', qui ne peut    */
                                        /* etre evidemment son propre voisin (c'est cela qui rend "un peu" redondant un test contenu */
                                        /* dans 'PARCOURS_D_UNE_STRUCTURE_LINEAIRE(...)' concernant le 'point_central_courant', mais */
                                        /* qui est malgre tout conserve : on ne sait jamais...).                                     */
                         DEFV(Int,INIT(rayon_des_spheres,UNDEF));
                                        /* Pour definir les surfaces des imbriquees les unes dans les autres...                      */

                         DEFV(pointI_3D,point_central_courant);

                         DEFV(pointI_3D,DdTb1(POINTERs
                                             ,liste_des_voisins_du_point_courant
                                             ,nombre_de_voisins_cherches
                                             ,tMalo(MUL2(nombre_de_voisins_cherches,SIZE(pointI_3D)),pointI_3D)
                                              )
                              );
                                        /* Definition et allocation du vecteur contenant les voisins du point courant.               */

                         EGAL(rayon_des_spheres,CHOY(amplitude_X,amplitude_Y,amplitude_Z));
                                        /* Initialisation du rayon des spheres...                                                    */

                         INITIALISATION_POINT_3D(point_central_courant,X,Y,Z);

                         begin_nouveau_block
                              Bblock
                              DEFV(Int,INIT(index_des_voisins,UNDEF));
                              DoIn(index_des_voisins,PREMIER_VOISIN,LSTX(PREMIER_VOISIN,nombre_de_voisins_cherches),I)
                                   Bblock
                                   INITIALISATION_POINT_3D(LISTE_DES_VOISINS(INDX(index_des_voisins,PREMIER_VOISIN))
                                                          ,PREX(Xmin)
                                                          ,PREY(Ymin)
                                                          ,PREZ(Zmin)
                                                           );
                                        /* Initialisation de la liste des voisins sur un point impossible (hors album...). En fait,  */
                                        /* cela ne sert a rien, mais c'est plus propre...                                            */
                                   Eblock
                              EDoI
                              Eblock
                         end_nouveau_block

                         Tant(IL_FAUT(iterer_la_recherche_des_voisins_du_point_central_courant))
                              Bblock
                                        /* Definition du cube courant de centre 'point_central_courant' :                            */
                                        /*                                                                                           */
                                        /*                                                                                           */
                                        /*                        H ---------- G                                                     */
                                        /*                                                                                           */
                                        /*                      / .          / |                                                     */
                                        /*                     /  .         /  |                                                     */
                                        /*                    /   .        /   |                                                     */
                                        /*                        .            |                                                     */
                                        /*                  D ---------- C     |                                                     */
                                        /*                                                                                           */
                                        /*                  |     E .....|.... F                                                     */
                                        /*                  |            |                                                           */
                                        /*                  |   .        |   /                                                       */
                                        /*                  |  .         |  /                                                        */
                                        /*                  | .          | /                                                         */
                                        /*                                                                                           */
                                        /*                  A ---------- B                                                           */
                                        /*                                                                                           */

                              PARCOURS_D_UNE_STRUCTURE_LINEAIRE(cX_AD__,cX_BC__
                                                               ,cY_AB__,cY_CD__
                                                               ,cZ_ABCD,cZ_ABCD
                                                                );
                                        /* Exploration de la face {A,B,C,D} (verticale avant).                                       */
                              PARCOURS_D_UNE_STRUCTURE_LINEAIRE(cX_EH__,cX_FG__
                                                               ,cY_EF__,cY_GH__
                                                               ,cZ_EFGH,cZ_EFGH
                                                                );
                                        /* Exploration de la face {E,F,G,H} (verticale arriere).                                     */

                              PARCOURS_D_UNE_STRUCTURE_LINEAIRE(cX_AEHD,cX_AEHD
                                                               ,cY_AE__,cY_DH__
                                                               ,cZ_AD__,cZ_EH__
                                                                );
                                        /* Exploration de la face {A,E,H,D} (verticale gauche).                                      */
                              PARCOURS_D_UNE_STRUCTURE_LINEAIRE(cX_BFGC,cX_BFGC
                                                               ,cY_BF__,cY_CG__
                                                               ,cZ_BC__,cZ_FG__
                                                                );
                                        /* Exploration de la face {B,F,G,C} (verticale droite).                                      */

                              PARCOURS_D_UNE_STRUCTURE_LINEAIRE(cX_AE__,cX_BF__
                                                               ,cY_ABFE,cY_ABFE
                                                               ,cZ_AB__,cZ_EF__
                                                                );
                                        /* Exploration de la face {A,B,F,E} (horizontale dessous).                                   */
                              PARCOURS_D_UNE_STRUCTURE_LINEAIRE(cX_DH__,cX_CG__
                                                               ,cY_DCGH,cY_DCGH
                                                               ,cZ_DC__,cZ_HG__
                                                                );
                                        /* Exploration de la face {D,C,G,H} (horizontale dessus).                                    */

                              INCR(amplitude_X,PasX);
                              INCR(amplitude_Y,PasY);
                              INCR(amplitude_Z,PasZ);
                                        /* Passage a un cube "superieur" (c'est-a-dire englobant les cubes precedents...).           */

                              INCR(rayon_des_spheres,CHOY(PasX,PasY,PasZ));
                                        /* Passage a une sphere "superieure" (si besoin est...).                                     */
                              Eblock
                         ETan

                         FdTb1(liste_des_voisins_du_point_courant,nombre_de_voisins_cherches,pointI_3D,ADRESSE_PLUS_DEFINIE);
                                        /* Liberation du vecteur contenant la liste des voisins.                                     */
                         Eblock
                    ATes
                         Bblock
                         Eblock
                    ETes
                    Eblock
               end_album
               Eblock
          ATes
               Bblock
               Test__CODE_ERREUR__ERREUR07;
               Eblock
          ETes

          EDEFV(album,album_d_images);
                                        /* Definition de l'album d'images a explorer.                                                */

          Eblock
     end_nouveau_block

     RETU_Commande;
     Eblock
ECommande



Copyright © Jean-François COLONNA, 2019-2024.
Copyright © CMAP (Centre de Mathématiques APpliquées) UMR CNRS 7641 / École polytechnique, Institut Polytechnique de Paris, 2019-2024.