STL 파일을 기호가 있는 거리 함수로 변환
개시하다 
기호 거리 함수(Signed Distance Function:SDF)에 대한 자세한 내용은 다음을 참조하십시오.
$$
f(x)=\begin{cases}d(x,∂Ω)\quad if\quad x∈Ω\\-d(x,∂Ω)\quad if\quad x∈Ω^{c}\\\end{cases}
$$
여기,Ω는 다각형면의 경계이다.
개요 
ASCII 형식의 STL 파일을 SDF 데이터로 변환합니다.유체 해석 등 물리 시뮬레이션의 스크래치를 실현하려면 복잡한 경계 조건의 도입은 매우 큰 장애물이다.이럴 때는 사이드 인터페이스의 SDF 데이터가 있으면 매우 편리하다.
STL에서 SDF로의 변환 사용basilisk.basilisk의 설치는 다음과 같습니다.
소스 코드 
기호 거리 함수를 가진 원본 코드를 csv로 출력합니다.Basilisk C로 구현됩니다.basilisk의 example Basilisk - src/examples/distance.c 을 참고했습니다.#include <sys/stat.h>
#include "grid/octree.h"
#include "utils.h"
#include "distance.h"
#include "fractions.h"
void mk_outfilepath(char *outfilepath, char *stlfilename, char *output_dir){
    char *ptr;
    char *ptr2;
    char *buf;
    ptr = strtok(stlfilename, "/");
    while(ptr != NULL) {
        buf = ptr;      
        ptr = strtok(NULL, "/");
    }
    ptr2 = strtok(buf, ".");
    sprintf(outfilepath,"%s%s_sdf.csv", output_dir, ptr2);
}
int main(int argc,char *argv[]){
    char *input_file = argv[1];
    char *output_dir = argv[2];
    int grids = atoi(argv[3]);
    mkdir(output_dir,0755);
    coord *p = input_stl (fopen (input_file, "r"));
    coord min, max;
    bounding_box (p, &min, &max);  
    double maxl = -HUGE;
    foreach_dimension()
        if (max.x - min.x > maxl)
            maxl = max.x - min.x;
    init_grid (grids);
    size (1.2*maxl);
    origin ((max.x + min.x)/2. - L0/2,
        (max.y + min.y)/2. - L0/2,
        (max.z + min.z)/2. - L0/2);
    scalar d[];
    distance (d, p);
    FILE *fp;
    char outfilepath[256];
    mk_outfilepath(outfilepath,input_file,output_dir);
    if ((fp = fopen(outfilepath, "w")) == NULL) {
        printf("file open error!!\n");
        exit(EXIT_FAILURE);
    }
    fprintf(fp,"x,y,z,distance\n");
    foreach() fprintf(fp,"%lf,%lf,%lf,%lf\n",x,y,z,d[]);
    fclose(fp);
}
실행 stl2sdf <stlfile_path> <output_dir> <grid_size>
option
설명
stlfile_path
STL 파일 경로
output_dir
출력 디렉토리(자동 생성)
grid_size
기호 거리 함수를 가진 공간 분할수
output_원본 STL 파일 이름에서 삭제합니다.stl +sdf.csv를 내보냅니다.
csv 파일의 내용은 x, y,z 좌표와 각 좌표의 기호 거리 함수입니다.객체는 양수 값이고 외부는 음수 값입니다.다음 그림은 Stand Bunny의 예입니다.
 
 
 
 
GitHub
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(STL 파일을 기호가 있는 거리 함수로 변환), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/JmpM/items/785f45b8ff30368f50b7
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
#include <sys/stat.h>
#include "grid/octree.h"
#include "utils.h"
#include "distance.h"
#include "fractions.h"
void mk_outfilepath(char *outfilepath, char *stlfilename, char *output_dir){
    char *ptr;
    char *ptr2;
    char *buf;
    ptr = strtok(stlfilename, "/");
    while(ptr != NULL) {
        buf = ptr;      
        ptr = strtok(NULL, "/");
    }
    ptr2 = strtok(buf, ".");
    sprintf(outfilepath,"%s%s_sdf.csv", output_dir, ptr2);
}
int main(int argc,char *argv[]){
    char *input_file = argv[1];
    char *output_dir = argv[2];
    int grids = atoi(argv[3]);
    mkdir(output_dir,0755);
    coord *p = input_stl (fopen (input_file, "r"));
    coord min, max;
    bounding_box (p, &min, &max);  
    double maxl = -HUGE;
    foreach_dimension()
        if (max.x - min.x > maxl)
            maxl = max.x - min.x;
    init_grid (grids);
    size (1.2*maxl);
    origin ((max.x + min.x)/2. - L0/2,
        (max.y + min.y)/2. - L0/2,
        (max.z + min.z)/2. - L0/2);
    scalar d[];
    distance (d, p);
    FILE *fp;
    char outfilepath[256];
    mk_outfilepath(outfilepath,input_file,output_dir);
    if ((fp = fopen(outfilepath, "w")) == NULL) {
        printf("file open error!!\n");
        exit(EXIT_FAILURE);
    }
    fprintf(fp,"x,y,z,distance\n");
    foreach() fprintf(fp,"%lf,%lf,%lf,%lf\n",x,y,z,d[]);
    fclose(fp);
}
stl2sdf <stlfile_path> <output_dir> <grid_size>
설명
stlfile_path
STL 파일 경로
output_dir
출력 디렉토리(자동 생성)
grid_size
기호 거리 함수를 가진 공간 분할수
output_원본 STL 파일 이름에서 삭제합니다.stl +sdf.csv를 내보냅니다.
csv 파일의 내용은 x, y,z 좌표와 각 좌표의 기호 거리 함수입니다.객체는 양수 값이고 외부는 음수 값입니다.다음 그림은 Stand Bunny의 예입니다.
 
  
 GitHub
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(STL 파일을 기호가 있는 거리 함수로 변환), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/JmpM/items/785f45b8ff30368f50b7
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
Reference
이 문제에 관하여(STL 파일을 기호가 있는 거리 함수로 변환), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/JmpM/items/785f45b8ff30368f50b7텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)