2013-06-27 3 views
1

큰 STL 파일을 읽고 구문 분석하는 방법은 무엇입니까? 3D STL 파일을 볼 응용 프로그램을 작성합니다. 3D STL 파일은 2 진 또는 ACSII 일 수 있습니다. sdcard에서 STL 파일을 읽고 OpenGL을 사용하여 렌더링 할 데이터를 파싱해야합니다. 그러나 3D STL이 클 때 "메모리 부족"현상이 나타납니다. 이 문제를 해결하는 방법. 나는 형식면과 꼭지점을 저장하기 위해 두 명의 arraylists를 사용합니다. 이것은 JVM의 최대 메모리 할당을 늘리는 것입니다 같은 상황에서 메모리 부족 문제가 해결큰 STL 파일을 읽고 구문 분석하는 방법은 무엇입니까?

private void processBinarySTL(){ 
    Thread processThread =new Thread(new Runnable() { 

     @Override 
     public void run() { 
      // TODO Auto-generated method stub 
      File file=new File("/mnt/sdcard/3D/Lost_Pleiade_Ready.stl"); 

      InputStream inputStream = null; 
      try { 
       inputStream = mContext.getContentResolver().openInputStream(Uri.fromFile(file)); 
       int n = 0; 
       byte[] buffer = new byte[4]; 
       inputStream.skip(80); 
       n = inputStream.read(buffer); 
       System.out.println("n=="+n); 
       int size=getIntWithLittleEndian(buffer,0); 
       System.out.println("size=="+size); 
       List<Float> normalList=new ArrayList<Float>(); 
       List<Float> vertexList = new ArrayList<Float>(); 
       for (int i = 0; i < size; i++) { 
        //normal 
        for(int k=0;k<3;k++){ 
        inputStream.read(buffer); 
        normalList.add(Float.intBitsToFloat(getIntWithLittleEndian(buffer, 0))); 
        } 


        for(int j=0;j<3;j++){ 
        inputStream.read(buffer); 
        float x = Float.intBitsToFloat(getIntWithLittleEndian(buffer, 0)); 
        inputStream.read(buffer); 
        float y = Float.intBitsToFloat(getIntWithLittleEndian(buffer, 0)); 
        inputStream.read(buffer); 
        float z = Float.intBitsToFloat(getIntWithLittleEndian(buffer, 0)); 
        adjustMaxMin(x, y, z); 
        vertexList.add(x); 
        vertexList.add(y); 
        vertexList.add(z); 
        } 
        inputStream.skip(2); 

       } 
       System.out.println("normalList size== "+normalList.size()); 
       System.out.println("vertexList size== "+vertexList.size()); 
      } catch (FileNotFoundException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      }finally{ 
       if(inputStream!=null) 
        try { 
         inputStream.close(); 
        } catch (IOException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
        } 
      } 

     } 
    }); 
    processThread.start(); 
} 
+1

는 http://code.j3d.org/javadoc/org/j3d/loaders/stl/STLFileReader.html –

+0

@KarthikT을 찾고 있습니다 답장을 보내 주셔서 감사합니다. 나는이 자원을 모른다. 나는 그것을 공부할 것이다. – Judy

+0

@ KarthikT j3d에 대해 살펴 보겠습니다. 하지만 그건 내 해결책이 아니야. 안드로이드 응용 프로그램에서 "view 3D STL File"을 구현해야합니다. – Judy

답변

1

가장 쉬운 방법 :

아래의 코드는 "이진 STL 파일을 읽고 분석"구현됩니다. 이는 -Xmx 명령 줄 스위치를 사용하고 더 큰 최대 메모리 사용량을 지정하여 설정할 수 있습니다.

예 : java Main -Xmx 2G은 프로그램 Main의 최대 메모리 사용량을 2GB로 설정합니다. 기본 최대 메모리 할당은 실제 메모리의 1/4입니다.

참조 : http://javarevisited.blogspot.sg/2011/11/hotspot-jvm-options-java-examples.html

0

여전히 문제에 대한 솔루션을 필요로하는 경우 나도 몰라. 귀하의 포스트가 작은 STL 바이너리 리더를 개발하여 정말로 도움이되었으므로 나는 당신에게 뭔가를 돌려주고 싶습니다. 나는 또한 내 자신의 애플 리케이션과 함께 이러한 이상한 메모리 부족을 발견했다. 그 이유는 안드로이드는 기본적으로 (장치에 따라) 아주 작은 양의 메모리를 제공하기 때문입니다. API 버전 11 이전에는 수동으로 메모리를 늘려야했습니다. 이제 API 레벨 11을 사용하면 "largeHeap"을 사용하여 이러한 문제를 피할 수 있습니다. 그냥이처럼 보이는 당신의 안드로이드 매니페스트에 선언을 넣어 : "어떻게 안드로이드 응용 프로그램의 힙 크기를 증가시키기 위해"당신이 검색하여 여기에 스택 오버플로 다른 스레드에서 찾을 수

<application 
     android:largeHeap="true" 
       ....  > 
       .... 
</application> 

자세한 내용은.

0

메모리 문제는 arraylist를 사용하여 발생합니다. 기본적으로 java는 arraylist를 10의 크기로 초기화합니다. 11 번째 요소를 추가하면 배열이 새로운 배열에 복사되고 배열의 현재 크기를 전달할 때마다 공간이 두 배로 지정됩니다 (크기가 20이므로). 크기가 복사되고 배가됩니다. 당신은 arraylist를 성장시키지 않고 모든 값을 저장하기에 충분히 큰 크기로 초기화함으로써 이것을 해결할 수 있습니다.

List<Float> normalList=new ArrayList<Float>(sizeOfArray); 
List<Float> vertexList = new ArrayList<Float>(sizeOfOtherArray); 
관련 문제