IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Algorithmes et structures de données Discussion :

Vérifier l'existence d'un point dans un nuage de points


Sujet :

Algorithmes et structures de données

  1. #21
    Expert éminent Avatar de Graffito
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    5 993
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 5 993
    Points : 7 903
    Points
    7 903
    Par défaut
    il peut y avoir des erreurs de précision, le nuage de points étant lu depuis un fichier texte et le point cherché étant recalculé
    Aargh, j'avais pas vu .

    Avant d'appeler la fonction GetHashCode(), il faudra normaliser la coordonnée x, y, z en fonction de l'erreur de précision ce qui pourra donner 1 ou 2 coordonées normalisées.
    Ainsi, au leu de traiter une liste unique, on pourra être amené à traiter un maximum de 8 listes si x y et z sont tous les 3 proches du milieu des bornes de normalisation.

    Par exemple, si la précision est égale à 1/10 000 :
    on convertit V*10 000 en entier ou entier long N,
    si N modulo 5 =0, 2 valeurs normalisées N/10 et N/10 + 1
    si N modulo 5 < 5, 1 valeurs normalisée N/10
    si N modulo 5 > 5, 1 valeur normalisée N/10 + 1

    V = 1.00123 ==> N=10012 ==> Vnorm = 1001
    V= 1.00146 ==> N=10015 ==> Vnorm1 = 1001 et Vnorm2=1002
    V= 1.00187 ==> N=10019 ==> Vnorm = 1002
    " Le croquemitaine ! Aaaaaah ! Où ça ? " ©Homer Simpson

  2. #22
    Membre à l'essai
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2014
    Messages
    23
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2014
    Messages : 23
    Points : 19
    Points
    19
    Par défaut
    Actuellement je suis en stand-by j'attends des informations sur les paramètres d'export de ces points (arrondis, chiffres après la virgule).
    Je vais dans les prochains jours implémenter ta solution ce qui ne devrait pas être très long.

    Merci de ton aide, je posterai les temps d'exécution pour comparaison.

    Bon week-end.

    MilWolf.

  3. #23
    Membre à l'essai
    Homme Profil pro
    autodidacte
    Inscrit en
    Mai 2015
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Belgique

    Informations professionnelles :
    Activité : autodidacte
    Secteur : Finance

    Informations forums :
    Inscription : Mai 2015
    Messages : 16
    Points : 12
    Points
    12
    Par défaut
    Citation Envoyé par MilWolf Voir le message
    Bonjour à tous,
    -le programme est en Java (pas forcément une contrainte)
    Comme le suggère Graffito avec sa proposition d algorithme en C, le C permet d avoir un code très nettement plus rapide que Java.
    Maintenant si tu as déjà fait une ébauche UML, tu peux utiliser le C++ qui est aussi nettement plus rapide que Java.

  4. #24
    Membre à l'essai
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2014
    Messages
    23
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2014
    Messages : 23
    Points : 19
    Points
    19
    Par défaut
    Merci de ta suggestion mais ce n'est pas de mon ressort le programme doit être en Java.
    J'utilise déjà le c++ avec JNI pour ce qui est la lecture de fichiers propriétaires ou compressés, et j'ai un bon gain de performance.

    Pour la recherche du point le plus proche j'ai implémenté hier une structure de données de type octree et je gagne pas mal de temps, je pense coupler ça avec une recherche dichotomique (binary search) pour gagner encore plus.
    Je posterai le code pour l'octree et la recherche de points.

  5. #25
    Membre à l'essai
    Homme Profil pro
    autodidacte
    Inscrit en
    Mai 2015
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Belgique

    Informations professionnelles :
    Activité : autodidacte
    Secteur : Finance

    Informations forums :
    Inscription : Mai 2015
    Messages : 16
    Points : 12
    Points
    12
    Par défaut
    Quel est le contexte de ton projet (si c est pas indiscret).
    Imprimantes 3D ???

  6. #26
    Membre à l'essai
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2014
    Messages
    23
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2014
    Messages : 23
    Points : 19
    Points
    19
    Par défaut
    C'est plutôt vaste mais le sujet principal est la voxelisation de données lidar terrestres et aéroportées.
    Le but est d'extraire des données en forêt comme la densité de surface foliaire ou la quantité de lumière arrivant au sol.

  7. #27
    Membre à l'essai
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2014
    Messages
    23
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2014
    Messages : 23
    Points : 19
    Points
    19
    Par défaut
    Bonsoir à tous,

    Comme je l'avais dit je laisse le code sur le forum, le code est fait depuis deux semaines mais je n'ai pas eu le temps de poster.

    Le principe de l'algorithme est la recherche des intersections entre une sphère et les nœuds feuilles d'un octree.
    La sphère a pour centre le point recherché et pour diamètre l'intervalle de recherche (marge d'erreur qui peut être due aux arrondis).
    Je donne au diamètre (ou marge d'erreur) une valeur de 0.0025 mètres soit 2.5mm.

    Donc au final je fais une recherche incrémentale des points contenus dans les noeuds feuilles intersectés par la sphère.
    La recherche dichotomique sera implémenté plus tard, pour le moment comme le temps de recherche est très raisonnable je suis passé à autre chose.

    La classe structure de données de type Octree:

    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
     
    private final static Logger logger = Logger.getLogger(Octree.class);
     
        private Point3F[] points;
        private Point3F minPoint;
        private Point3F maxPoint;
        private int depth;
        private Node root;
        private List<Node> leafs;
     
        private final int maximumPoints;
     
        public final static short BINARY_SEARCH = 0;
        public final static short INCREMENTAL_SEARCH = 1;
     
        public Octree(int maximumPoints){
            this.maximumPoints = maximumPoints;
            depth = 0;
        }
     
        public void build(){
     
            if(points != null){
     
                root = new Node(minPoint, maxPoint);
     
                for(int i=0;i<points.length;i++){
     
                    root.insertPoint(this, i);
                }
     
            }else{
                logger.warn("Attempt to build octree but points array is null");
            }
        }
     
        public List<Node> getLeafs(){
     
            leafs = new ArrayList<>();
     
            if(root != null){
                getChilds(root);
            }
     
            return leafs;
        }
     
        private void getChilds(Node node){
     
            if(node.hasChilds()){
     
                for(short i=0;i<8;i++){
                    Node child = node.getChild(i);
                    if(child.isLeaf()){
                        leafs.add(child);
                    }else{
                        getChilds(child);
                    }
                }
     
            }
        }
     
        public Node traverse(Point3F point){
     
            Node node = null;
     
            if(root != null){
     
                node = root;
     
                while(node.hasChilds()){
                    short indice = node.get1DIndiceFromPoint(point);
     
                    //le point est à l'extérieur de la bounding-box
                    if(indice == -1){
                        return null;
                    }
     
                    Node child = node.getChild(indice);
                    node = child;
     
                }
            }
     
            return node;
        }
     
        public Point3F searchNearestPoint(Point3F point, short type, float errorMargin){
     
            switch(type){
                case BINARY_SEARCH:
                    return binarySearchNearestPoint(point, errorMargin);
                case INCREMENTAL_SEARCH:
                    return incrementalSearchNearestPoint(point, errorMargin);
            }
     
            return null;
        }
     
        public boolean isPointBelongsToPointcloud(Point3F point, float errorMargin, short type){
     
            Point3F incrementalSearchNearestPoint = searchNearestPoint(point, type, errorMargin);
     
     
            boolean test = false;
            if(incrementalSearchNearestPoint != null){
                float distance = point.distanceTo(incrementalSearchNearestPoint);
     
     
                if(distance < errorMargin){
                    test = true;
                }
            }
     
            return test;
        }
     
        private Point3F binarySearchNearestPoint(Point3F point, float errorMargin){
     
            Point3F nearestPoint = null;
     
            //sera implémenté par la suite
     
            return nearestPoint;
        }
     
        private Point3F incrementalSearchNearestPoint(Point3F point, float errorMargin){
     
            Point3F nearestPoint = null;
     
            if(root != null){
     
                int[] nearestPoints;
                float distance = 99999999;
     
     
                    List<Node> nodesIntersectingSphere = new ArrayList<>();
     
                    Sphere searchArea = new Sphere(point, errorMargin);
     
                    incrementalSphereIntersectionSearch(nodesIntersectingSphere, root, searchArea);
     
                    for(Node node : nodesIntersectingSphere){
     
                        nearestPoints = node.getPoints();
     
                        if(nearestPoints != null){
     
                            for (int pointToTest : nearestPoints) {
     
                                float dist = point.distanceTo(points[pointToTest]);
     
                                if(dist < distance){
                                    distance = dist;
                                    nearestPoint = points[pointToTest];
                                }
                            }
                        }
                    }
                }
     
     
            return nearestPoint;
        }
     
        private void incrementalSphereIntersectionSearch(List<Node> nodesIntersectingSphere, Node node, Sphere sphere){
     
            if(sphereIntersection(node, sphere)){
     
                if(node.hasChilds()){
     
                    for(short i=0;i<8;i++){
                        Node child = node.getChild(i);
                        boolean intersect = sphereIntersection(child, sphere);
     
                        if(child.isLeaf() && intersect){
                            nodesIntersectingSphere.add(child);
                        }else{
                            incrementalSphereIntersectionSearch(nodesIntersectingSphere, child, sphere);
                        }
                    }
     
                }else{
                    nodesIntersectingSphere.add(node);
                }
            }
        }
     
        private boolean sphereIntersection(Node node, Sphere sphere){
     
            float dist_squared = sphere.getRadius()*sphere.getRadius();
     
            Point3F sphereCenter = sphere.getCenter();
     
            Point3F nodeBottomCorner = node.getMinPoint();
            Point3F nodeTopCorner = node.getMaxPoint();
     
            if (sphereCenter.x < nodeBottomCorner.x){
                dist_squared -= Math.pow(sphereCenter.x - nodeBottomCorner.x, 2);
            }else if (sphereCenter.x > nodeTopCorner.x) {
                dist_squared -= Math.pow(sphereCenter.x - nodeTopCorner.x, 2);
            }
     
            if (sphereCenter.y < nodeBottomCorner.y){
                dist_squared -= Math.pow(sphereCenter.y - nodeBottomCorner.y, 2);
            }else if (sphereCenter.y > nodeTopCorner.y) {
                dist_squared -= Math.pow(sphereCenter.y - nodeTopCorner.y, 2);
            }
     
            if (sphereCenter.z < nodeBottomCorner.z){
                dist_squared -= Math.pow(sphereCenter.z - nodeBottomCorner.z, 2);
            }else if (sphereCenter.z > nodeTopCorner.z) {
                dist_squared -= Math.pow(sphereCenter.z - nodeTopCorner.z, 2);
            }
     
            return dist_squared > 0;
        }
     
        public int getMaximumPoints() {
            return maximumPoints;
        }
     
        public Point3F[] getPoints() {
            return points;
        }
     
        public int getDepth() {
            return depth;
        }
     
        public void setDepth(int depth) {
            this.depth = depth;
        }
     
        public void setPoints(Point3F[] points) {
            this.points = points;
        }
     
        public void setMinPoint(Point3F minPoint) {
            this.minPoint = minPoint;
        }
     
        public void setMaxPoint(Point3F maxPoint) {
            this.maxPoint = maxPoint;
        }

    La classe Node:

    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
     
    public class Node {
     
        private final static Logger logger = Logger.getLogger(Node.class);
     
        private boolean leaf;
        private Node[] childs;
        private int[] points;
        private int pointNumber;
        private Point3F minPoint;
        private Point3F maxPoint;
     
        public Node(Point3F minPoint, Point3F maxPoint){
     
            this.minPoint = minPoint;
            this.maxPoint = maxPoint;
     
            init();
        }
     
        public Node(Node parent, short indice){
     
            if(parent != null && indice >= 0 && indice <= 7){
     
                init();
     
                short[] decToBin = decToBin(indice);
     
                short indiceX = decToBin[0];
                short indiceY = decToBin[1];
                short indiceZ = decToBin[2];
     
                float minPointX, minPointY, minPointZ;
                float maxPointX, maxPointY, maxPointZ;
     
                if(indiceX == 0){
                    minPointX = parent.minPoint.x;
                    maxPointX = (parent.minPoint.x+parent.maxPoint.x)/2.0f;
                }else{
                    minPointX = (parent.minPoint.x+parent.maxPoint.x)/2.0f;
                    maxPointX = parent.maxPoint.x;
                }
     
                if(indiceY == 0){
                    minPointY = parent.minPoint.y;
                    maxPointY = (parent.minPoint.y+parent.maxPoint.y)/2.0f;
                }else{
                    minPointY = (parent.minPoint.y+parent.maxPoint.y)/2.0f;
                    maxPointY = parent.maxPoint.y;
                }
     
                if(indiceZ == 0){
                    minPointZ = parent.minPoint.z;
                    maxPointZ = (parent.minPoint.z+parent.maxPoint.z)/2.0f;
                }else{
                    minPointZ = (parent.minPoint.z+parent.maxPoint.z)/2.0f;
                    maxPointZ = parent.maxPoint.z;
                }
     
                minPoint = new Point3F(minPointX, minPointY, minPointZ);
                maxPoint = new Point3F(maxPointX, maxPointY, maxPointZ);
     
            }else{
                logger.error("Cannot instantiate node cause parent is null or indice is not range between 0 to 7");
            }
        }
     
        private void init(){
            leaf = true;
            childs = null;
        }
     
        public boolean isLeaf() {
            return leaf;
        }
     
        public void insertPoint(Octree octree, int indice){
     
            //la condition est vraie quand aucun point n'a déjà été ajouté au noeud
            if(childs == null && points == null){
     
                points = new int[octree.getMaximumPoints()];
                pointNumber = 0;
            }
     
     
            if(childs == null && points !=null){
     
                if(pointNumber < points.length){ 
     
                    points[pointNumber] = indice;
                    pointNumber++;
                }else{ //la condition est vraie quand le nombre maximum de points dans le noeud a été atteint
     
                    // on crée les enfants
                    subdivide();
     
                    //on replace tous les points du noeud dans ses enfants
                    for(int i = 0 ; i< pointNumber;i++){
                        insertPoint(octree, points[i]);
                    }
     
                    points = null;
                }
     
     
            }
     
            if(childs != null){
     
                //on détermine dans quel enfant se trouve le point
                int childContainingPointID;
                Point3F point = octree.getPoints()[indice];
     
                Point3I indices = get3DIndicesFromPoint(point);
     
                childContainingPointID = get1DIndiceFrom3DIndices(indices.x, indices.y, indices.z);
     
                if(isInsideRange(childContainingPointID, 0, 7)){
                    //on ajoute le point à l'enfant
                    childs[childContainingPointID].insertPoint(octree, indice);
                }else{
                    logger.error("");
                }
     
            }
        }
     
        public short get1DIndiceFromPoint(Point3F point){
     
            Point3I indices = get3DIndicesFromPoint(point);
     
            if(indices == null){
                return -1;
            }
     
            return get1DIndiceFrom3DIndices(indices.x, indices.y, indices.z);
        }
     
        public Point3I get3DIndicesFromPoint(Point3F point){
     
            int indiceX = (int)((point.x-minPoint.x)/((maxPoint.x-minPoint.x)/2.0f));
            int indiceY = (int)((point.y-minPoint.y)/((maxPoint.y-minPoint.y)/2.0f));
            int indiceZ = (int)((point.z-minPoint.z)/((maxPoint.z-minPoint.z)/2.0f));
     
            //cas où la coordonnée du point est sur la limite maximum de la bounding-box
            if(indiceX == 2){indiceX = 1;}
            if(indiceY == 2){indiceY = 1;}
            if(indiceZ == 2){indiceZ = 1;}
     
            //cas où la coordonnée est à l'extérieur de la bounding-box
            if(!isInsideRange(indiceX, 0, 1) || !isInsideRange(indiceY, 0, 1) || !isInsideRange(indiceZ, 0, 1)){
                return null;
            }
     
            return new Point3I(indiceX, indiceY, indiceZ);
        }
     
        public boolean hasChilds(){
     
            return childs != null;
        }
     
        public int[] getPoints() {
     
            if(points != null){
                return Arrays.copyOf(points, pointNumber);
            }
            return null;
        }
     
        private void subdivide(){
     
            childs = new Node[8];
     
            for(short i=0;i<8;i++){
                childs[i] = new Node(this, i);
            }
     
            leaf = false;
        }
     
        private short get1DIndiceFrom3DIndices(int bit1, int bit2, int bit3){
     
            short dec = 0;
     
            dec += bit1 * Math.pow(2, 2);
            dec += bit2 * Math.pow(2, 1);
            dec += bit3 * Math.pow(2, 0);
     
            return dec;
        }
     
        private short[] decToBin(short decimal){
     
            short[] result = new short[3];
            short tmp = decimal;
     
            for(short i=2 ; i >= 0 ; i--){
                result[i] = (short) (tmp%2);
                tmp = (short) (tmp/2);
            }
     
            return result;
        }
     
        public Node getChild(short indice){
     
            if(childs != null && indice <= 7 && indice >= 0){
                return childs[indice];
            }
     
            return null;
        }
     
        private boolean isInsideRange(int value, int min, int max){
            return (value >= min && value <= max);
        }
     
        public Point3F getMinPoint() {
            return minPoint;
        }
     
        public Point3F getMaxPoint() {
            return maxPoint;
        }

    La classe Point3F:

    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
     
    public class Point3F  implements Comparable<Point3F>{
     
        public float x, y, z;
     
        public Point3F() {
            this.x = 0;
            this.y = 0;
            this.z = 0;
        }
     
        public Point3F(float x, float y, float z) {
     
            this.x = x;
            this.y = y;
            this.z = z;
        }
     
        public float distanceTo(Point3F point){
     
            return (float) Math.sqrt(Math.pow(point.x-x, 2)+Math.pow(point.y-y, 2)+Math.pow(point.z-z, 2));
        }
     
        @Override
        public int compareTo(Point3F o) {
            if(o.x > this.x){
                return -1;
            }else if(o.x < this.x){
                return 1;
            }else{
                if(o.y > this.y){
                    return -1;
                }else if(o.y < this.y){
                    return 1;
                }else{
                    if(o.z > this.z){
                        return -1;
                    }else if(o.z < this.z){
                        return 1;
                    }else{
                        return 0;
                    }
                }
            }
        }
    }

    L'utilisation se fait comme ceci:
    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
     
    public class OctreeFactory {
     
        private final static Logger logger = Logger.getLogger(OctreeFactory.class);
        public final static int DEFAULT_MAXIMUM_POINT_NUMBER = 50;
     
     
        public static Octree createOctreeFromPointFile(File file, int maximumPointNumber, boolean sortPoints){
     
            List<Point3F> pointList = new ArrayList<>();
     
            try(BufferedReader reader = new BufferedReader(new FileReader(file))) {
     
                String line;
                boolean isInit = false;
                String separator = " ";
                int count = 1;
     
                while((line = reader.readLine()) != null){
     
                    if(!isInit){
                        if(line.contains(",") && line.contains(".")){
                            separator = ",";
                        }
     
                        String[] split = line.split(separator);
                        if(split.length > 3){
                            logger.info("Point file contains more columns than necessary, parsing the three first");
                        }else if(split.length < 3){
                            logger.error("Point file doesn't contains valid columns!");
                            reader.close();
                            return null;
                        }
     
                        isInit = true;
                    }
     
                    String[] split = line.split(separator);
                    if(split.length < 3){
                        logger.error("Error parsing line "+count);
                        reader.close();
                        return null;
                    }
     
                    pointList.add(new Point3F(Float.valueOf(split[0]), Float.valueOf(split[1]), Float.valueOf(split[2])));
                    count++;
                }
     
            } catch (FileNotFoundException ex) {
                logger.error(ex);
            } catch (IOException ex) {
                logger.error(ex);
            }
     
            Point3F[] points = new Point3F[pointList.size()];
     
            float minPointX = 0, minPointY = 0, minPointZ = 0;
            float maxPointX = 0, maxPointY = 0, maxPointZ = 0;
     
            boolean init = false;
            for(Point3F point : pointList){
     
                if(!init){
                    minPointX = point.x;
                    minPointY = point.y;
                    minPointZ = point.z;
     
                    maxPointX = point.x;
                    maxPointY = point.y;
                    maxPointZ = point.z;
     
                    init = true;
     
                }else{
     
                    if(point.x > maxPointX){
                        maxPointX = point.x;
                    }else if(point.x < minPointX){
                        minPointX = point.x;
                    }
     
                    if(point.y > maxPointY){
                        maxPointY = point.y;
                    }else if(point.y < minPointY){
                        minPointY = point.y;
                    }
     
                    if(point.z > maxPointZ){
                        maxPointZ = point.z;
                    }else if(point.z < minPointZ){
                        minPointZ = point.z;
                    }
                }
            }
     
            Point3F minPoint = new Point3F(minPointX, minPointY, minPointZ);
            Point3F maxPoint = new Point3F(maxPointX, maxPointY, maxPointZ);
     
            if(sortPoints){
                Collections.sort(pointList);
            }
     
            pointList.toArray(points);
     
            Octree octree = new Octree(maximumPointNumber);
     
            octree.setPoints(points);
            octree.setMinPoint(minPoint);
            octree.setMaxPoint(maxPoint);
     
            return octree;
        }


    Le code a été nettoyé lors de l'écriture de ce message mais il est possible qu'il y ait des classes qui ne servent à rien.
    N'hésitez pas à critiquer et à me faire part d'éventuels bugs.

    Merci à ceux qui m'ont aidé.
    Bonne soirée!

    MilWolf.

Discussions similaires

  1. Réponses: 2
    Dernier message: 10/03/2012, 14h54
  2. mettre plusieur couleur de points dans un nuage de points
    Par cedrix57 dans le forum ODS et reporting
    Réponses: 3
    Dernier message: 05/03/2009, 09h04
  3. Mettre en avant un point dans un nuage de point
    Par FabienN dans le forum BIRT
    Réponses: 27
    Dernier message: 20/08/2008, 10h20
  4. Help : changer la couleur d'une point dans un Nuages de point
    Par yukka dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 16/05/2007, 11h30
  5. vérifier l'existance d'une table dans une base de donnée
    Par zidenne dans le forum Bases de données
    Réponses: 1
    Dernier message: 31/10/2005, 11h39

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo