function liveviewCA4(hObject, eventdata, Empty_Button, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, plotopt, lvText, lvSlider, type, lcs, POS)
data = get(Empty_Button,'UserData');

testok = 0;

if (data.motion == 0) && (data.motionC == 0)
    return;
end

if data.afscomputed(1) + data.afscomputed(2) == 0
    return;
end

lvc = lcs(max(data.motion, data.motionC),:);

isFIRPOL = data.isFP;
isINNPOL = data.isIP;
isAFS = data.isAFS;

bu = data.choosen;
buC = data.choosenC;

if data.motion == 0
    
    data.choosenC(data.motionC) = 0;
    
    Axes1 = AxesC;
    Axes2 = AxesA;
    
    AFS1 = data.afsC;
    AFS2 = data.afsA;
    
    FIRPOL1 = data.FIRPOLC;
    FIRPOL2 = data.FIRPOLA;
    
    INNPOL1 = data.INNPOLC;
    INNPOL2 = data.INNPOLA;
    
    AxesSOL1 = AxesSOLC;
    AxesSOL2 = AxesSOLA;
    
    xl1 = data.xlc;
    xl2 = data.xla;
    yl1 = data.ylc;
    yl2 = data.yla;
    
    full.is1 = data.full.isC;
    full.AFS1 = data.full.AFSC;
    full.lines1 = data.full.linesC;
    full.valid1 = data.full.validC;
    full.dim1 = data.full.dimC;
    
    full.is2 = data.full.isA;
    full.AFS2 = data.full.AFSA;
    full.lines2 = data.full.linesA;
    full.valid2 = data.full.validA;
    full.dim2 = data.full.dimA;
    
    LR1 = data.V*data.S;
    LR2 = data.U';
    
    lin1 = data.t;
    lin2 = data.x;
    
    fix1 = data.fixC;
    fix2 = data.fixA;
    
    mk = 'ox';
    ch = data.motionC;
    
    choosen1 = data.choosenC;
    choosen2 = data.choosen;
    
    given1 = data.givenc;
    given2 = data.givena;
    
    idfix = data.motionC;
    
    linscale1 = data.S(2:4,2:4);
    linscale2 = data.S(1,1);
        
else
    
    data.choosen(data.motion) = 0;
    
    Axes1 = AxesA;
    Axes2 = AxesC;
    
    AFS1 = data.afsA;
    AFS2 = data.afsC;
    
    FIRPOL1 = data.FIRPOLA;
    FIRPOL2 = data.FIRPOLC;
    
    INNPOL1 = data.INNPOLA;
    INNPOL2 = data.INNPOLC;
    
    AxesSOL1 = AxesSOLA;
    AxesSOL2 = AxesSOLC;
    
    xl1 = data.xla;
    xl2 = data.xlc;
    yl1 = data.yla;
    yl2 = data.ylc;
    
    full.is1 = data.full.isA;
    full.AFS1 = data.full.AFSA;
    full.lines1 = data.full.linesA;
    full.valid1 = data.full.validA;
    full.dim1 = data.full.dimA;
    
    full.is2 = data.full.isC;
    full.AFS2 = data.full.AFSC;
    full.lines2 = data.full.linesC;
    full.valid2 = data.full.validC;
    full.dim2 = data.full.dimC;
    
    LR1 = data.U*data.S;
    LR2 = data.V';
    
    lin1 = data.x;
    lin2 = data.t;
    
    fix1 = data.fixA;
    fix2 = data.fixC;
    
    mk = 'xo';
    ch = data.motion;
    
    choosen1 = data.choosen;
    choosen2 = data.choosenC;
    
    given1 = data.givena;
    given2 = data.givenc;
    
    idfix = data.motion;
    
    linscale1 = data.S(2:4,2:4);
    linscale2 = data.S(1,1);
end

col = 'k';
sty = '-';

AFSview(1,:) = get(Axes1,'view');
AFScam(1,:) = get(Axes1,'cameraPosition');
AFStar(1,:) = get(Axes1, 'cameraTarget');
AFSupv(1,:) = get(Axes1, 'cameraUpVector');

AFSview(2,:) = get(Axes2,'view');
AFScam(2,:) = get(Axes2,'cameraPosition');
AFStar(2,:) = get(Axes2, 'cameraTarget');
AFSupv(2,:) = get(Axes2, 'cameraUpVector');

if type > 6
    if data.is3dmouse
        
        v1 = AFScam(1,:)-AFStar(1,:);
        v2 = AFSupv(1,:);
        v3 = null([v1; v2]);

        if det([v1;v2;v3']) < 0
            ViewTrafo = [v1; v2; -v3'];
        else
            ViewTrafo = [v1; v2; v3'];
        end

        dactx = ((ViewTrafo)^(-1)*([1 1 -1].*POS([2 3 1]))')';
        actx = data.actx + dactx;
        
        if actx(1) < AFS1.xm(1)   actx(1) = AFS1.xm(1);  end
        if actx(1) > AFS1.xm(2)   actx(1) = AFS1.xm(2);  end
        if actx(2) < AFS1.ym(1)   actx(2) = AFS1.ym(1);  end
        if actx(2) > AFS1.ym(2)   actx(2) = AFS1.ym(2);  end
        if actx(3) < AFS1.zm(1)   actx(3) = AFS1.zm(1);  end
        if actx(3) > AFS1.zm(2)   actx(3) = AFS1.zm(2);  end
        
        data.actx = actx;
        
        x = actx(1);
        y = actx(2);
        z = actx(3);
        
        set(lvSlider(1),'Value', x);
        set(lvSlider(2),'Value', y);
        set(lvSlider(3),'Value', z);
       
        set(lvText(4), 'String', num2str(x));
        set(lvText(5), 'String', num2str(y));
        set(lvText(6), 'String', num2str(z));
    end
elseif type > 3
    
    x = get(lvSlider(type-3),'Value');
    set(lvText(type), 'String', num2str(x));
    
    x = get(lvSlider(1),'Value');
    y = get(lvSlider(2),'Value');
    z = get(lvSlider(3),'Value');
    
elseif type > 0
    
    mi = get(lvSlider(type),'Min');
    ma = get(lvSlider(type),'Max');
    
    x = getsetvar(lvText(3+type), mi, ma, 0, 1);
    
    set(lvSlider(type),'Value', x);
    
    x = get(lvSlider(1),'Value');
    y = get(lvSlider(2),'Value');
    z = get(lvSlider(3),'Value');
    
elseif type < 1
    
    x = data.actx(1);
    y = data.actx(2);
    z = data.actx(3);
    
end

actx = [x y z];
xn = actx/norm(actx,2);
psi = acos(xn(3));
phi = atan2(xn(2),xn(1));

i1m = floor((phi+pi)*AFS1.raybase.m1/2/pi);
i1p = ceil((phi+pi)*AFS1.raybase.m1/2/pi);
i2m = floor(psi*AFS1.raybase.m2/pi);
i2p = ceil(psi*AFS1.raybase.m2/pi);

if testok
    ok = 0;
    for seg=1:AFS1.afs.nseg

        idmm = find((AFS1.afs.seg{seg}.i1==i1m).*(AFS1.afs.seg{seg}.i2==i2m),1);
        idmp = find((AFS1.afs.seg{seg}.i1==i1m).*(AFS1.afs.seg{seg}.i2==i2p),1);
        idpm = find((AFS1.afs.seg{seg}.i1==i1p).*(AFS1.afs.seg{seg}.i2==i2m),1);
        idpp = find((AFS1.afs.seg{seg}.i1==i1p).*(AFS1.afs.seg{seg}.i2==i2p),1);

        all = [idmm idmp idpm idpp];
        if length(all) >= 3
            if length(all) == 4
                TRI = [all(1:3); all([1 2 4]); all([1 3 4]); all([2 3 4])];
            else
                TRI = all;
            end
            for i=size(TRI,1)
                tri = TRI(i,:);

                ninn = AFS1.afs.seg{seg}.INN(tri,:)\[1;1;1];
                nout = AFS1.afs.seg{seg}.OUT(tri,:)\[1;1;1];
                if AFS1.afs.seg{seg}.INN(tri(1),:)*ninn < 0
                    ninn = -ninn;
                end
                if AFS1.afs.seg{seg}.OUT(tri(1),:)*nout < 0
                    nout = -nout;
                end

                if ((AFS1.afs.seg{seg}.INN(tri(1),:)*ninn) < (actx*ninn)) && ((AFS1.afs.seg{seg}.OUT(tri(1),:)*nout) > (actx*nout))
                    ok = 1;
                    break;
                end
            end
        end
        if ok
            break;
        end
    end
else
    ok = 1;
end

lvonoff = [1 0];

plotafsCA4(Axes1, Axes2, AxesSOL1, AxesSOL2, AFS1, AFS2, FIRPOL1, FIRPOL2, INNPOL1, INNPOL2, isFIRPOL, isINNPOL, isAFS, lcs, lvc, lvonoff, plotopt)

plotaddsCA4(Axes1, Axes2, AxesSOL1, AxesSOL2, AFS1, AFS2, fix1, fix2, LR1, LR2, choosen1, lin1, lin2, given1, given2, linscale1,linscale2, idfix, x, y, z, lcs, lvc, lvonoff, plotopt, ok, 1, actx)

data.actx = actx;

if lvonoff(1) == 1
    set(Axes1, 'cameraPosition', AFScam(1,:));
    set(Axes1, 'cameraTarget', AFStar(1,:));
    set(Axes1, 'cameraUpVector', AFSupv(1,:));
elseif lvonoff(1) == 0
    set(Axes1,'view',AFSview(1,:));
end

if lvonoff(2) == 1
    set(Axes2, 'cameraPosition', AFScam(2,:));
    set(Axes2, 'cameraTarget', AFStar(2,:));
    set(Axes2, 'cameraUpVector', AFSupv(2,:));
elseif lvonoff(2) == 0
    set(Axes2,'view',AFSview(2,:));
end

data.choosen = bu;
data.choosenC = buC;

set(Empty_Button,'UserData',data);
