// File: Luthaf[P]zeopp/feature.cc
// Function: FEATURE::createFeatures(ATOM_NETWORK*, VORONOI_NETWORK*, DIJKSTRA_NETWORK*, std::basic_fstream<char, std::char_traits<char>>&, int, char*)
int FEATURE::createFeatures(ATOM_NETWORK *uc,VORONOI_NETWORK *origVNet, DIJKSTRA_NETWORK *origDNet, std::fstream &output, int initIndex,char *name){
    nfeatures = 0;
    features = std::vector<int> ();
    feature_node_mapping = std::vector<int> ();
    segmentChannel(uc);
    if(nfeatures == 0){
        std::cerr << "Error occurred during channel segmentation. No features were found." << "\n"
        << "Exiting..." << "\n";
        exit(1);
    }
    
    std::vector< std::vector<int> > nodesForFeatures = std::vector < std::vector<int> > (nfeatures, std::vector<int> ());
    std::vector<FEATURE> featChannels = std::vector<FEATURE> ();
    for(unsigned int i = 0; i < feature_node_mapping.size(); i++){
        nodesForFeatures[feature_node_mapping[i]].push_back(reverseIDMappings.find(i)->second);
    }
    
    
    int zeroVecs [3][3] = {{0, 0, 0},{ 0, 0, 0}, {0, 0, 0}};
    
    for(int i = 0; i < nfeatures; i++){
        DIJKSTRA_NETWORK featNet;
        DIJKSTRA_NETWORK::filterDnetEdges(nodesForFeatures[i], origVNet, &featNet);
        std::vector<bool> infoStorage; std::vector<CHANNEL> channels;
        findChannels(&featNet, &infoStorage, &channels);
        int dim;
        if(channels.size() != 0){
            dim = channels[0].dimensionality;
            featChannels.push_back(FEATURE(nodesForFeatures[i], origDNet, dim, channels[0].basis));
        }
        else{
            dim = 0;
            featChannels.push_back(FEATURE(nodesForFeatures[i], origDNet, 0, zeroVecs));
        }
        featChannels[i].writeToVMD("feature", initIndex + i, output);
        std::cout << "@@ " << name << " Feature " << initIndex + i << " volume = " << featChannels[i].calculateVolume() << "\n";
        featChannels[i].calculateSurfaceArea(uc,&nodes,&feature_node_mapping,i,name,initIndex + i);
    }
    return nfeatures;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x7a0, %rsp            # imm = 0x7A0
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x6f8(%rbp)
movl $0x0, 0x1b8(%rax)
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x52a0
leaq -0x48(%rbp), %rdi
callq 0xd0d0
movq -0x6f8(%rbp), %rdi
addq $0x1c0, %rdi            # imm = 0x1C0
leaq -0x48(%rbp), %rsi
callq 0x22ed0
leaq -0x48(%rbp), %rdi
callq 0xec80
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x52a0
leaq -0x60(%rbp), %rdi
callq 0xd0d0
movq -0x6f8(%rbp), %rdi
addq $0x1d8, %rdi            # imm = 0x1D8
leaq -0x60(%rbp), %rsi
callq 0x22ed0
leaq -0x60(%rbp), %rdi
callq 0xec80
movq -0x6f8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xd8840
movq -0x6f8(%rbp), %rax
cmpl $0x0, 0x1b8(%rax)
jne 0xd80d8
movq 0x19af5b(%rip), %rdi    # 0x272ff0
leaq 0x12384c(%rip), %rsi    # 0x1fb8e8
callq 0x5540
movq %rax, %rdi
leaq 0x12157a(%rip), %rsi    # 0x1f9625
callq 0x5540
movq %rax, %rdi
leaq 0x123260(%rip), %rsi    # 0x1fb31a
callq 0x5540
movq %rax, %rdi
leaq 0x12155c(%rip), %rsi    # 0x1f9625
callq 0x5540
movl $0x1, %edi
callq 0x67c0
movq -0x6f8(%rbp), %rax
movslq 0x1b8(%rax), %rax
movq %rax, -0x710(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x90(%rbp)
movq $0x0, -0x80(%rbp)
leaq -0x90(%rbp), %rdi
movq %rdi, -0x708(%rbp)
callq 0xd0d0
leaq -0x91(%rbp), %rdi
movq %rdi, -0x700(%rbp)
callq 0x12b40
movq -0x710(%rbp), %rsi
movq -0x708(%rbp), %rdx
movq -0x700(%rbp), %rcx
leaq -0x78(%rbp), %rdi
callq 0xaedd0
jmp 0xd8145
leaq -0x91(%rbp), %rdi
callq 0x13770
leaq -0x90(%rbp), %rdi
callq 0xec80
leaq -0xc0(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x52a0
leaq -0xc0(%rbp), %rdi
callq 0xe0540
movl $0x0, -0xc4(%rbp)
movq -0x6f8(%rbp), %rdi
movl -0xc4(%rbp), %eax
movq %rax, -0x718(%rbp)
addq $0x1d8, %rdi            # imm = 0x1D8
callq 0x10090
movq %rax, %rcx
movq -0x718(%rbp), %rax
cmpq %rcx, %rax
jae 0xd829e
movq -0x6f8(%rbp), %rdi
addq $0x1d8, %rdi            # imm = 0x1D8
movl -0xc4(%rbp), %eax
movl %eax, %esi
callq 0xed60
movslq (%rax), %rsi
leaq -0x78(%rbp), %rdi
callq 0x10890
movq -0x6f8(%rbp), %rdi
movq %rax, -0x728(%rbp)
addq $0x30, %rdi
movl -0xc4(%rbp), %eax
movl %eax, -0xd4(%rbp)
leaq -0xd4(%rbp), %rsi
callq 0x102e0
movq %rax, -0x720(%rbp)
jmp 0xd8213
movq -0x720(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x10350
movq -0x728(%rbp), %rdi
movq %rax, %rsi
addq $0x4, %rsi
callq 0xd1b0
jmp 0xd8242
jmp 0xd8244
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0xd8186
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x91(%rbp), %rdi
callq 0x13770
leaq -0x90(%rbp), %rdi
callq 0xec80
jmp 0xd8834
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xd881f
leaq -0x100(%rbp), %rdi
xorl %esi, %esi
movl $0x24, %edx
callq 0x52a0
movl $0x0, -0x104(%rbp)
movq -0x6f8(%rbp), %rcx
movl -0x104(%rbp), %eax
cmpl 0x1b8(%rcx), %eax
jge 0xd87e8
leaq -0x168(%rbp), %rdi
callq 0x94790
jmp 0xd82e2
movslq -0x104(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x10890
movq %rax, %rsi
leaq -0x180(%rbp), %rdi
callq 0xeec0
jmp 0xd8303
movq -0x18(%rbp), %rsi
leaq -0x180(%rbp), %rdi
leaq -0x168(%rbp), %rdx
callq 0x94c30
jmp 0xd831c
leaq -0x180(%rbp), %rdi
callq 0xec80
leaq -0x1a8(%rbp), %rdi
movq %rdi, -0x738(%rbp)
callq 0xf670
leaq -0x1c0(%rbp), %rdi
movq %rdi, -0x730(%rbp)
callq 0x84dd0
movq -0x738(%rbp), %rsi
movq -0x730(%rbp), %rdx
leaq -0x168(%rbp), %rdi
callq 0xc9b80
jmp 0xd836a
leaq -0x1c0(%rbp), %rdi
callq 0xd62c0
cmpq $0x0, %rax
je 0xd84d6
xorl %eax, %eax
movl %eax, %esi
leaq -0x1c0(%rbp), %rdi
callq 0xe0560
movl 0x108(%rax), %eax
movl %eax, -0x1c4(%rbp)
movslq -0x104(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x10890
movq %rax, %rsi
leaq -0x448(%rbp), %rdi
callq 0xeec0
jmp 0xd83bd
movq -0x20(%rbp), %rax
movq %rax, -0x748(%rbp)
movl -0x1c4(%rbp), %eax
movl %eax, -0x73c(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x1c0(%rbp), %rdi
callq 0xe0560
movq -0x748(%rbp), %rdx
movl -0x73c(%rbp), %ecx
movq %rax, %r8
addq $0x10c, %r8             # imm = 0x10C
leaq -0x430(%rbp), %rdi
leaq -0x448(%rbp), %rsi
callq 0xe05b0
jmp 0xd8410
leaq -0xc0(%rbp), %rdi
leaq -0x430(%rbp), %rsi
callq 0xe0580
jmp 0xd8425
leaq -0x430(%rbp), %rdi
callq 0xe06f0
leaq -0x448(%rbp), %rdi
callq 0xec80
jmp 0xd8595
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xd87da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x180(%rbp), %rdi
callq 0xec80
jmp 0xd87da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xd87c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xd84c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x430(%rbp), %rdi
callq 0xe06f0
leaq -0x448(%rbp), %rdi
callq 0xec80
jmp 0xd87c2
movl $0x0, -0x1c4(%rbp)
movslq -0x104(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x10890
movq %rax, %rsi
leaq -0x6c8(%rbp), %rdi
callq 0xeec0
jmp 0xd8501
movq -0x20(%rbp), %rdx
leaq -0x6b0(%rbp), %rdi
leaq -0x6c8(%rbp), %rsi
xorl %ecx, %ecx
leaq -0x100(%rbp), %r8
callq 0xe05b0
jmp 0xd8523
leaq -0xc0(%rbp), %rdi
leaq -0x6b0(%rbp), %rsi
callq 0xe0580
jmp 0xd8538
leaq -0x6b0(%rbp), %rdi
callq 0xe06f0
leaq -0x6c8(%rbp), %rdi
callq 0xec80
jmp 0xd8595
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xd8584
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x6b0(%rbp), %rdi
callq 0xe06f0
leaq -0x6c8(%rbp), %rdi
callq 0xec80
jmp 0xd87c2
movslq -0x104(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x89b70
movq %rax, -0x758(%rbp)
leaq -0x6e9(%rbp), %rdi
movq %rdi, -0x750(%rbp)
callq 0x5900
movq -0x750(%rbp), %rdx
leaq 0x12335c(%rip), %rsi    # 0x1fb92c
leaq -0x6e8(%rbp), %rdi
callq 0x47530
jmp 0xd85de
movq -0x758(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl -0x104(%rbp), %eax
addl %eax, %edx
movq -0x28(%rbp), %rcx
leaq -0x6e8(%rbp), %rsi
callq 0xc9150
jmp 0xd8602
leaq -0x6e8(%rbp), %rdi
callq 0x5300
leaq -0x6e9(%rbp), %rdi
callq 0x55d0
movq 0x19a99f(%rip), %rdi    # 0x272fc0
leaq 0x12330c(%rip), %rsi    # 0x1fb934
callq 0x5540
movq %rax, -0x760(%rbp)
jmp 0xd8636
movq -0x760(%rbp), %rdi
movq 0x10(%rbp), %rsi
callq 0x5540
movq %rax, -0x768(%rbp)
jmp 0xd864f
movq -0x768(%rbp), %rdi
leaq 0x1232db(%rip), %rsi    # 0x1fb938
callq 0x5540
movq %rax, -0x770(%rbp)
jmp 0xd866b
movq -0x770(%rbp), %rdi
movl -0x2c(%rbp), %esi
movl -0x104(%rbp), %eax
addl %eax, %esi
callq 0x58d0
movq %rax, -0x778(%rbp)
jmp 0xd868b
movq -0x778(%rbp), %rdi
leaq 0x1232a9(%rip), %rsi    # 0x1fb942
callq 0x5540
movq %rax, -0x780(%rbp)
jmp 0xd86a7
movslq -0x104(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x89b70
movq %rax, %rdi
callq 0xd8b00
movsd %xmm0, -0x788(%rbp)
jmp 0xd86cc
movsd -0x788(%rbp), %xmm0
movq -0x780(%rbp), %rdi
callq 0x5980
movq %rax, -0x790(%rbp)
jmp 0xd86e9
movq -0x790(%rbp), %rdi
leaq 0x120f2e(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0xd86fe
movslq -0x104(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x89b70
movq -0x6f8(%rbp), %rcx
movq %rax, %rdi
movq -0x10(%rbp), %rsi
movq %rcx, %rdx
addq $0x60, %rdx
addq $0x1d8, %rcx            # imm = 0x1D8
movl -0x104(%rbp), %r8d
movq 0x10(%rbp), %r9
movl -0x2c(%rbp), %r10d
addl %r8d, %r10d
movq %rsp, %rax
movl %r10d, (%rax)
callq 0xd94c0
jmp 0xd874c
leaq -0x1c0(%rbp), %rdi
callq 0x84ee0
leaq -0x1a8(%rbp), %rdi
callq 0xf9b0
leaq -0x168(%rbp), %rdi
callq 0xf840
movl -0x104(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x104(%rbp)
jmp 0xd82bb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xd87b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x6e8(%rbp), %rdi
callq 0x5300
leaq -0x6e9(%rbp), %rdi
callq 0x55d0
leaq -0x1c0(%rbp), %rdi
callq 0x84ee0
leaq -0x1a8(%rbp), %rdi
callq 0xf9b0
leaq -0x168(%rbp), %rdi
callq 0xf840
jmp 0xd881f
movq -0x6f8(%rbp), %rax
movl 0x1b8(%rax), %eax
movl %eax, -0x794(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xe07d0
leaq -0x78(%rbp), %rdi
callq 0x108b0
movl -0x794(%rbp), %eax
addq $0x7a0, %rsp            # imm = 0x7A0
popq %rbp
retq
leaq -0xc0(%rbp), %rdi
callq 0xe07d0
leaq -0x78(%rbp), %rdi
callq 0x108b0
movq -0xa0(%rbp), %rdi
callq 0x58f0